Skip to main content

Async database support for Python. (Custom Patched version, this is not the original version.)

Project description

Databases

This is a drop-in replacement for the original databases package

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.

Requirements: Python 3.8+


Installation

$ pip install databases-patched

Database drivers supported are:

You can install the required database drivers with:

$ pip install databases-patched[asyncpg]
$ pip install databases-patched[aiopg]
$ pip install databases-patched[aiomysql]
$ pip install databases-patched[asyncmy]
$ pip install databases-patched[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-patched[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)

for examples of how to start using databases together with SQLAlchemy core expressions.

— ⭐️ —

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

databases_patched-0.9.1.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

databases_patched-0.9.1-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file databases_patched-0.9.1.tar.gz.

File metadata

  • Download URL: databases_patched-0.9.1.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for databases_patched-0.9.1.tar.gz
Algorithm Hash digest
SHA256 09d5868fbd02e1e61574f26c7e419aaf2883b7f052fa78ec341ad51d7e3493cd
MD5 d3d037d2c55e722dc0fb2bf06345f1a0
BLAKE2b-256 4bb389c3b2ee52d01c247d9ca2f1922fb939ecd79781fed181bf91e490ecaef1

See more details on using hashes here.

File details

Details for the file databases_patched-0.9.1-py3-none-any.whl.

File metadata

File hashes

Hashes for databases_patched-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6021c5d11c8b36b0a94b4acb4e4b7a8009ce5c05d65730d94e7a677eb8c18cef
MD5 df8b87961cba6156930e49c74d057fc5
BLAKE2b-256 0dc5da3a6e8ff00f2fc71d029dbb5d707dc831b769eea009128db2b28ba9274a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page