← Winnitude! Search  ·  Reader Mode (1308 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 81 LINKS

GitHub - encode/databases: Async database support for Python. 🗄

This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Repository navigation

databases
Public archive

About

Async database support for Python. 🗄

www.encode.io/databases/

Topics

asyncio mysql postgres sqlalchemy sqlite

Resources

Readme BSD-3-Clause license

Contributing

Contributing Activity Custom properties

Stars

4.0k stars

Watchers

6 watching

Forks

396 forks Report repository
Branches

Tags
Go to Branches page Go to Tags page

Latest commit

 

History


335 Commits
View commit history for this file.

Folders and files

Name Name Last commit message Last commit date
.github .github    
databases databases    
docs docs    
scripts scripts    
tests tests    
.gitignore .gitignore    
CHANGELOG.md CHANGELOG.md    
LICENSE.md LICENSE.md    
README.md README.md    
mkdocs.yml mkdocs.yml    
requirements.txt requirements.txt    
setup.cfg setup.cfg    
setup.py setup.py    

Repository files navigation

Databases

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

It allows you to make queries using the powerful 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 , Sanic , Responder , Quart , aiohttp , Tornado , or FastAPI .

Documentation : https://www.encode.io/databases/

Requirements : Python 3.8+


Installation

$ pip install databases

Database drivers supported are:

You can install the required database drivers with:

$ 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 migrations then you still have to install a synchronous DB driver: psycopg2 for PostgreSQL and pymysql for MySQL.


Quickstart

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

$ 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.

# 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 for examples of how to start using databases together with SQLAlchemy core expressions.

-- ⭐️ --

Databases is BSD licensed code. Designed & built in Brighton, England.

About

Async database support for Python. 🗄

www.encode.io/databases/

Topics

asyncio mysql postgres sqlalchemy sqlite

Resources

Readme BSD-3-Clause license

Contributing

Contributing Activity Custom properties

Stars

4.0k stars

Watchers

6 watching

Forks

396 forks Report repository

Releases

Packages

Used by

Contributors

Languages