Flask-MySQLdb


NameFlask-MySQLdb JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/alexferl/flask-mysqldb
SummaryMySQLdb extension for Flask
upload_time2023-10-04 22:48:15
maintainer
docs_urlNone
authorAlexandre Ferland
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Flask-MySQLdb [![Build Status](https://app.travis-ci.com/alexferl/flask-mysqldb.svg?branch=master)](https://app.travis-ci.com/alexferl/flask-mysqldb)
================

Flask-MySQLdb provides MySQL connection for Flask.

Quickstart
----------

First, you _may_ need to install some dependencies for [mysqlclient](https://github.com/PyMySQL/mysqlclient)
if you don't already have them, see [here](https://github.com/PyMySQL/mysqlclient#install).

Second, install Flask-MySQLdb:
```shell
pip install flask-mysqldb
```

Flask-MySQLdb depends, and will install for you, recent versions of Flask
(1.0.4 or later) and [mysqlclient](https://github.com/PyMySQL/mysqlclient).
Flask-MySQLdb is compatible with and tested with Python 3.8+.

Next, add a ``MySQL`` instance to your code:

```python
from flask import Flask
from flask_mysqldb import MySQL

app = Flask(__name__)

# Required
app.config["MYSQL_USER"] = "user"
app.config["MYSQL_PASSWORD"] = "password"
app.config["MYSQL_DB"] = "database"
# Extra configs, optional:
app.config["MYSQL_CURSORCLASS"] = "DictCursor"
app.config["MYSQL_CUSTOM_OPTIONS"] = {"ssl": {"ca": "/path/to/ca-file"}}  # https://mysqlclient.readthedocs.io/user_guide.html#functions-and-attributes

mysql = MySQL(app)

@app.route("/")
def users():
    cur = mysql.connection.cursor()
    cur.execute("""SELECT user, host FROM mysql.user""")
    rv = cur.fetchall()
    return str(rv)

if __name__ == "__main__":
    app.run(debug=True)
```

Other configuration directives can be found [here](http://flask-mysqldb.readthedocs.io/en/latest/#configuration).

Why
---
Why would you want to use this extension versus just using MySQLdb by itself?
The only reason is that the extension was made using Flask's best practices in relation
to resources that need caching on the [app context](https://flask.palletsprojects.com/en/2.0.x/appcontext/).
What that means is that the extension will manage creating and teardown the connection to MySQL
for you while with if you were just using MySQLdb you would have to do it yourself.


Resources
---------

- [Documentation](http://flask-mysqldb.readthedocs.org/en/latest/)
- [PyPI](https://pypi.python.org/pypi/Flask-MySQLdb)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alexferl/flask-mysqldb",
    "name": "Flask-MySQLdb",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Alexandre Ferland",
    "author_email": "me@alexferl.com",
    "download_url": "https://files.pythonhosted.org/packages/b4/80/afdc313a3875d15c3ba32de302fa161890ceae762576f890fde74f29a01d/Flask-MySQLdb-2.0.0.tar.gz",
    "platform": null,
    "description": "Flask-MySQLdb [![Build Status](https://app.travis-ci.com/alexferl/flask-mysqldb.svg?branch=master)](https://app.travis-ci.com/alexferl/flask-mysqldb)\n================\n\nFlask-MySQLdb provides MySQL connection for Flask.\n\nQuickstart\n----------\n\nFirst, you _may_ need to install some dependencies for [mysqlclient](https://github.com/PyMySQL/mysqlclient)\nif you don't already have them, see [here](https://github.com/PyMySQL/mysqlclient#install).\n\nSecond, install Flask-MySQLdb:\n```shell\npip install flask-mysqldb\n```\n\nFlask-MySQLdb depends, and will install for you, recent versions of Flask\n(1.0.4 or later) and [mysqlclient](https://github.com/PyMySQL/mysqlclient).\nFlask-MySQLdb is compatible with and tested with Python 3.8+.\n\nNext, add a ``MySQL`` instance to your code:\n\n```python\nfrom flask import Flask\nfrom flask_mysqldb import MySQL\n\napp = Flask(__name__)\n\n# Required\napp.config[\"MYSQL_USER\"] = \"user\"\napp.config[\"MYSQL_PASSWORD\"] = \"password\"\napp.config[\"MYSQL_DB\"] = \"database\"\n# Extra configs, optional:\napp.config[\"MYSQL_CURSORCLASS\"] = \"DictCursor\"\napp.config[\"MYSQL_CUSTOM_OPTIONS\"] = {\"ssl\": {\"ca\": \"/path/to/ca-file\"}}  # https://mysqlclient.readthedocs.io/user_guide.html#functions-and-attributes\n\nmysql = MySQL(app)\n\n@app.route(\"/\")\ndef users():\n    cur = mysql.connection.cursor()\n    cur.execute(\"\"\"SELECT user, host FROM mysql.user\"\"\")\n    rv = cur.fetchall()\n    return str(rv)\n\nif __name__ == \"__main__\":\n    app.run(debug=True)\n```\n\nOther configuration directives can be found [here](http://flask-mysqldb.readthedocs.io/en/latest/#configuration).\n\nWhy\n---\nWhy would you want to use this extension versus just using MySQLdb by itself?\nThe only reason is that the extension was made using Flask's best practices in relation\nto resources that need caching on the [app context](https://flask.palletsprojects.com/en/2.0.x/appcontext/).\nWhat that means is that the extension will manage creating and teardown the connection to MySQL\nfor you while with if you were just using MySQLdb you would have to do it yourself.\n\n\nResources\n---------\n\n- [Documentation](http://flask-mysqldb.readthedocs.org/en/latest/)\n- [PyPI](https://pypi.python.org/pypi/Flask-MySQLdb)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "MySQLdb extension for Flask",
    "version": "2.0.0",
    "project_urls": {
        "Homepage": "https://github.com/alexferl/flask-mysqldb"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "31c4c91b4a704c1e2467ecfd2c47a9c6f609af37cde7380698aace19dce24f53",
                "md5": "7d7e08abde7b1975138987aeeb006dee",
                "sha256": "84ad09c862a408709538d237712426a6d34ed3e7e971effd6c7186023cd2f2f5"
            },
            "downloads": -1,
            "filename": "Flask_MySQLdb-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7d7e08abde7b1975138987aeeb006dee",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4869,
            "upload_time": "2023-10-04T22:48:13",
            "upload_time_iso_8601": "2023-10-04T22:48:13.403828Z",
            "url": "https://files.pythonhosted.org/packages/31/c4/c91b4a704c1e2467ecfd2c47a9c6f609af37cde7380698aace19dce24f53/Flask_MySQLdb-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b480afdc313a3875d15c3ba32de302fa161890ceae762576f890fde74f29a01d",
                "md5": "d1f85ef1a7be45b6c31d9ffa167ec929",
                "sha256": "4f3e15013a2d48c8eaccdebcfedc3b1c4a29be77de6e7c746ad589ab5afcd3ef"
            },
            "downloads": -1,
            "filename": "Flask-MySQLdb-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d1f85ef1a7be45b6c31d9ffa167ec929",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 4485,
            "upload_time": "2023-10-04T22:48:15",
            "upload_time_iso_8601": "2023-10-04T22:48:15.346633Z",
            "url": "https://files.pythonhosted.org/packages/b4/80/afdc313a3875d15c3ba32de302fa161890ceae762576f890fde74f29a01d/Flask-MySQLdb-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-04 22:48:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alexferl",
    "github_project": "flask-mysqldb",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "flask-mysqldb"
}
        
Elapsed time: 0.17387s