{"id":13424640,"url":"https://github.com/encode/databases","last_synced_at":"2025-05-13T15:09:16.625Z","repository":{"id":37405807,"uuid":"168684254","full_name":"encode/databases","owner":"encode","description":"Async database support for Python. 🗄","archived":false,"fork":false,"pushed_at":"2024-05-21T19:58:17.000Z","size":872,"stargazers_count":3901,"open_issues_count":132,"forks_count":262,"subscribers_count":51,"default_branch":"master","last_synced_at":"2025-04-23T18:53:58.090Z","etag":null,"topics":["asyncio","mysql","postgres","sqlalchemy","sqlite"],"latest_commit_sha":null,"homepage":"https://www.encode.io/databases/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/encode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/contributing.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-01T10:55:25.000Z","updated_at":"2025-04-21T14:01:26.000Z","dependencies_parsed_at":"2023-02-10T07:35:11.808Z","dependency_job_id":"10df090b-d737-4415-97bf-22a6a0144d62","html_url":"https://github.com/encode/databases","commit_stats":{"total_commits":281,"total_committers":61,"mean_commits":4.60655737704918,"dds":0.4590747330960854,"last_synced_commit":"ae3fb16f40201d9ed0ed31bea31a289127169568"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/encode%2Fdatabases","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/encode%2Fdatabases/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/encode%2Fdatabases/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/encode%2Fdatabases/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/encode","download_url":"https://codeload.github.com/encode/databases/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253969239,"owners_count":21992262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncio","mysql","postgres","sqlalchemy","sqlite"],"created_at":"2024-07-31T00:00:57.253Z","updated_at":"2025-05-13T15:09:11.604Z","avatar_url":"https://github.com/encode.png","language":"Python","readme":"# Databases\n\n\u003cp\u003e\n\u003ca href=\"https://github.com/encode/databases/actions\"\u003e\n    \u003cimg src=\"https://github.com/encode/databases/workflows/Test%20Suite/badge.svg\" alt=\"Test Suite\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://pypi.org/project/databases/\"\u003e\n    \u003cimg src=\"https://badge.fury.io/py/databases.svg\" alt=\"Package version\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\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\u003cp align=\"center\"\u003e\u0026mdash; ⭐️ \u0026mdash;\u003c/p\u003e\n\u003cp align=\"center\"\u003e\u003ci\u003eDatabases is \u003ca href=\"https://github.com/encode/databases/blob/master/LICENSE.md\"\u003eBSD licensed\u003c/a\u003e code. Designed \u0026 built in Brighton, England.\u003c/i\u003e\u003c/p\u003e\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","funding_links":[],"categories":["Third-Party Extensions","Python","Data Management \u0026 Processing","Database Clients","Database Drivers"],"sub_categories":["Databases","Database \u0026 Cloud Management"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fencode%2Fdatabases","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fencode%2Fdatabases","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fencode%2Fdatabases/lists"}