Skip to main content

Databases

Test Suite Package version

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/

Community: https://discuss.encode.io/c/databases

Requirements: Python 3.6+


Installation

$ pip install databases

You can install the required database drivers with:

$ pip install databases[postgresql]
$ pip install databases[mysql]
$ pip install databases[sqlite]

Driver support is provided using one of asyncpg, aiomysql, or aiosqlite.


Quickstart

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

$ pip install databases[sqlite]
$ 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:///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.

Metadata

Release files for databases-extended 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for databases-extended 0.4.1
File Size Uploaded
databases_extended-0.4.1.tar.gz 15.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for databases-extended 0.4.1
File Interpreter ABI Platform
databases_extended-0.4.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 36.3 kB

Release files / databases_extended-0.4.1.tar.gz

Download URL databases_extended-0.4.1.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
63e26225e07b0e431bce9833075c17bb60a9baf043a8d4cbb18480898738badc
BLAKE2b-256 checksum
How to use checksums
bf0e0daef26c9b3636814786ab8dd022f450a1c1a05bca7403cb9707f2440841
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

Release files / databases_extended-0.4.1-py2.py3-none-any.whl

Download URL databases_extended-0.4.1-py2.py3-none-any.whl
Size 20.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7c8ae1b152075769770493517ab788a12020a3a249cc9d91ad29cdf8d66534af
BLAKE2b-256 checksum
How to use checksums
81f84d3ead8f3a44a0609ef4abd7345544fe1903de9d6590c3640c7676a45a7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page