databases


Namedatabases JSON
Version 0.9.0 PyPI version JSON
download
home_pagehttps://github.com/encode/databases
SummaryAsync database support for Python.
upload_time2024-03-01 17:39:28
maintainer
docs_urlNone
authorTom Christie
requires_python>=3.8
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Databases

<p>
<a href="https://github.com/encode/databases/actions">
    <img src="https://github.com/encode/databases/workflows/Test%20Suite/badge.svg" alt="Test Suite">
</a>
<a href="https://pypi.org/project/databases/">
    <img src="https://badge.fury.io/py/databases.svg" alt="Package version">
</a>
</p>

Databases gives you simple asyncio support for a range of databases.

It allows you to make queries using the powerful [SQLAlchemy Core][sqlalchemy-core]
expression language, and provides support for PostgreSQL, MySQL, and SQLite.

Databases is suitable for integrating against any async Web framework, such as [Starlette][starlette],
[Sanic][sanic], [Responder][responder], [Quart][quart], [aiohttp][aiohttp], [Tornado][tornado], or [FastAPI][fastapi].

**Documentation**: [https://www.encode.io/databases/](https://www.encode.io/databases/)

**Requirements**: Python 3.8+

---

## Installation

```shell
$ pip install databases
```

Database drivers supported are:

* [asyncpg][asyncpg]
* [aiopg][aiopg]
* [aiomysql][aiomysql]
* [asyncmy][asyncmy]
* [aiosqlite][aiosqlite]

You can install the required database drivers with:

```shell
$ pip install databases[asyncpg]
$ pip install databases[aiopg]
$ pip install databases[aiomysql]
$ pip install databases[asyncmy]
$ pip install databases[aiosqlite]
```

Note that if you are using any synchronous SQLAlchemy functions such as `engine.create_all()` or [alembic][alembic] migrations then you still have to install a synchronous DB driver: [psycopg2][psycopg2] for PostgreSQL and [pymysql][pymysql] for MySQL.

---

## Quickstart

For this example we'll create a very simple SQLite database to run some
queries against.

```shell
$ pip install databases[aiosqlite]
$ pip install ipython
```

We can now run a simple example from the console.

Note that we want to use `ipython` here, because it supports using `await`
expressions directly from the console.

```python
# Create a database instance, and connect to it.
from databases import Database
database = Database('sqlite+aiosqlite:///example.db')
await database.connect()

# Create a table.
query = """CREATE TABLE HighScores (id INTEGER PRIMARY KEY, name VARCHAR(100), score INTEGER)"""
await database.execute(query=query)

# Insert some data.
query = "INSERT INTO HighScores(name, score) VALUES (:name, :score)"
values = [
    {"name": "Daisy", "score": 92},
    {"name": "Neil", "score": 87},
    {"name": "Carol", "score": 43},
]
await database.execute_many(query=query, values=values)

# Run a database query.
query = "SELECT * FROM HighScores"
rows = await database.fetch_all(query=query)
print('High Scores:', rows)
```

Check out the documentation on [making database queries](https://www.encode.io/databases/database_queries/)
for examples of how to start using databases together with SQLAlchemy core expressions.


<p align="center">&mdash; ⭐️ &mdash;</p>
<p align="center"><i>Databases is <a href="https://github.com/encode/databases/blob/master/LICENSE.md">BSD licensed</a> code. Designed & built in Brighton, England.</i></p>

[sqlalchemy-core]: https://docs.sqlalchemy.org/en/latest/core/
[sqlalchemy-core-tutorial]: https://docs.sqlalchemy.org/en/latest/core/tutorial.html
[alembic]: https://alembic.sqlalchemy.org/en/latest/
[psycopg2]: https://www.psycopg.org/
[pymysql]: https://github.com/PyMySQL/PyMySQL
[asyncpg]: https://github.com/MagicStack/asyncpg
[aiopg]: https://github.com/aio-libs/aiopg
[aiomysql]: https://github.com/aio-libs/aiomysql
[asyncmy]: https://github.com/long2ice/asyncmy
[aiosqlite]: https://github.com/omnilib/aiosqlite

[starlette]: https://github.com/encode/starlette
[sanic]: https://github.com/huge-success/sanic
[responder]: https://github.com/kennethreitz/responder
[quart]: https://gitlab.com/pgjones/quart
[aiohttp]: https://github.com/aio-libs/aiohttp
[tornado]: https://github.com/tornadoweb/tornado
[fastapi]: https://github.com/tiangolo/fastapi

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/encode/databases",
    "name": "databases",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Tom Christie",
    "author_email": "tom@tomchristie.com",
    "download_url": "https://files.pythonhosted.org/packages/76/de/ea55722907bd1b2389b01e362faa3c66a09d5a8463c13d44c80da7b32497/databases-0.9.0.tar.gz",
    "platform": null,
    "description": "# Databases\n\n<p>\n<a href=\"https://github.com/encode/databases/actions\">\n    <img src=\"https://github.com/encode/databases/workflows/Test%20Suite/badge.svg\" alt=\"Test Suite\">\n</a>\n<a href=\"https://pypi.org/project/databases/\">\n    <img src=\"https://badge.fury.io/py/databases.svg\" alt=\"Package version\">\n</a>\n</p>\n\nDatabases gives you simple asyncio support for a range of databases.\n\nIt allows you to make queries using the powerful [SQLAlchemy Core][sqlalchemy-core]\nexpression language, and provides support for PostgreSQL, MySQL, and SQLite.\n\nDatabases is suitable for integrating against any async Web framework, such as [Starlette][starlette],\n[Sanic][sanic], [Responder][responder], [Quart][quart], [aiohttp][aiohttp], [Tornado][tornado], or [FastAPI][fastapi].\n\n**Documentation**: [https://www.encode.io/databases/](https://www.encode.io/databases/)\n\n**Requirements**: Python 3.8+\n\n---\n\n## Installation\n\n```shell\n$ pip install databases\n```\n\nDatabase drivers supported are:\n\n* [asyncpg][asyncpg]\n* [aiopg][aiopg]\n* [aiomysql][aiomysql]\n* [asyncmy][asyncmy]\n* [aiosqlite][aiosqlite]\n\nYou can install the required database drivers with:\n\n```shell\n$ pip install databases[asyncpg]\n$ pip install databases[aiopg]\n$ pip install databases[aiomysql]\n$ pip install databases[asyncmy]\n$ pip install databases[aiosqlite]\n```\n\nNote that if you are using any synchronous SQLAlchemy functions such as `engine.create_all()` or [alembic][alembic] migrations then you still have to install a synchronous DB driver: [psycopg2][psycopg2] for PostgreSQL and [pymysql][pymysql] for MySQL.\n\n---\n\n## Quickstart\n\nFor this example we'll create a very simple SQLite database to run some\nqueries against.\n\n```shell\n$ pip install databases[aiosqlite]\n$ pip install ipython\n```\n\nWe can now run a simple example from the console.\n\nNote that we want to use `ipython` here, because it supports using `await`\nexpressions directly from the console.\n\n```python\n# Create a database instance, and connect to it.\nfrom databases import Database\ndatabase = Database('sqlite+aiosqlite:///example.db')\nawait database.connect()\n\n# Create a table.\nquery = \"\"\"CREATE TABLE HighScores (id INTEGER PRIMARY KEY, name VARCHAR(100), score INTEGER)\"\"\"\nawait database.execute(query=query)\n\n# Insert some data.\nquery = \"INSERT INTO HighScores(name, score) VALUES (:name, :score)\"\nvalues = [\n    {\"name\": \"Daisy\", \"score\": 92},\n    {\"name\": \"Neil\", \"score\": 87},\n    {\"name\": \"Carol\", \"score\": 43},\n]\nawait database.execute_many(query=query, values=values)\n\n# Run a database query.\nquery = \"SELECT * FROM HighScores\"\nrows = await database.fetch_all(query=query)\nprint('High Scores:', rows)\n```\n\nCheck out the documentation on [making database queries](https://www.encode.io/databases/database_queries/)\nfor examples of how to start using databases together with SQLAlchemy core expressions.\n\n\n<p align=\"center\">&mdash; \u2b50\ufe0f &mdash;</p>\n<p align=\"center\"><i>Databases is <a href=\"https://github.com/encode/databases/blob/master/LICENSE.md\">BSD licensed</a> code. Designed & built in Brighton, England.</i></p>\n\n[sqlalchemy-core]: https://docs.sqlalchemy.org/en/latest/core/\n[sqlalchemy-core-tutorial]: https://docs.sqlalchemy.org/en/latest/core/tutorial.html\n[alembic]: https://alembic.sqlalchemy.org/en/latest/\n[psycopg2]: https://www.psycopg.org/\n[pymysql]: https://github.com/PyMySQL/PyMySQL\n[asyncpg]: https://github.com/MagicStack/asyncpg\n[aiopg]: https://github.com/aio-libs/aiopg\n[aiomysql]: https://github.com/aio-libs/aiomysql\n[asyncmy]: https://github.com/long2ice/asyncmy\n[aiosqlite]: https://github.com/omnilib/aiosqlite\n\n[starlette]: https://github.com/encode/starlette\n[sanic]: https://github.com/huge-success/sanic\n[responder]: https://github.com/kennethreitz/responder\n[quart]: https://gitlab.com/pgjones/quart\n[aiohttp]: https://github.com/aio-libs/aiohttp\n[tornado]: https://github.com/tornadoweb/tornado\n[fastapi]: https://github.com/tiangolo/fastapi\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Async database support for Python.",
    "version": "0.9.0",
    "project_urls": {
        "Homepage": "https://github.com/encode/databases"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d5436035922af5471f1a196851831a1d5f403447401b395f474bf673efa8959f",
                "md5": "5766dcc37b1304104138c0a28c138e90",
                "sha256": "9ee657c9863b34f8d3a06c06eafbe1bda68af2a434b56996312edf1f1c0b6297"
            },
            "downloads": -1,
            "filename": "databases-0.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5766dcc37b1304104138c0a28c138e90",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 25580,
            "upload_time": "2024-03-01T17:39:26",
            "upload_time_iso_8601": "2024-03-01T17:39:26.352318Z",
            "url": "https://files.pythonhosted.org/packages/d5/43/6035922af5471f1a196851831a1d5f403447401b395f474bf673efa8959f/databases-0.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "76deea55722907bd1b2389b01e362faa3c66a09d5a8463c13d44c80da7b32497",
                "md5": "68d1c6389561f99fc1f4aa7fa2eb5312",
                "sha256": "d2f259677609bf187737644c95fa41701072e995dfeb8d2882f335795c5b61b0"
            },
            "downloads": -1,
            "filename": "databases-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "68d1c6389561f99fc1f4aa7fa2eb5312",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 31084,
            "upload_time": "2024-03-01T17:39:28",
            "upload_time_iso_8601": "2024-03-01T17:39:28.378796Z",
            "url": "https://files.pythonhosted.org/packages/76/de/ea55722907bd1b2389b01e362faa3c66a09d5a8463c13d44c80da7b32497/databases-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-01 17:39:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "encode",
    "github_project": "databases",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "databases"
}
        
Elapsed time: 0.22198s