Skip to main content

Databasez

databasez

🚀 Async database support for Python. 🚀

Test Suite Package version Supported Python versions


Documentation: https://databasez.dymmond.com 📚

Source Code: https://github.com/dymmond/databasez


Motivation

There is a great package from Encode that was doing what this package was forked to do.

From a need to extend to new drivers and newest technologies and adding extra features common and useful to the many, Databases was forked to become Databasez.

This package is 100% backwards compatible with Databases from Encode and will remain like this for the time being but adding extra features and regular updates as well as continuing to be community driven.

By the time this project was created, Databases was yet to merge possible SQLAlchemy 2.0 changes from the author of this package and therefore, this package aims to unblock a lot of the projects out there that want SQLAlchemy 2.0 with the best of databases with new features.

A lot of packages depends of Databases and this was the main reason for the fork of Databasez.

It allows you to make queries using the powerful SQLAlchemy Core expression language, and provides support for PostgreSQL, MySQL, SQLite and MSSQL.

Databasez is suitable for integrating against any async Web framework, such as Esmerald, Starlette, Sanic, Responder, Quart, aiohttp, Tornado, or FastAPI.

Databasez was built for Python 3.10+ and on the top of the newest SQLAlchemy 2 and gives you simple asyncio support for a range of databases.

Special notes

This package couldn't exist without Databases and the continuous work done by the amazing team behind it. For that reason, thank you!

Installation

$ pip install databasez

If you are interested in using the test client, you can also install:

$ pip install databasez[testing]

What does databasez support at the moment

Databasez currently supports nearly all async drivers of sqlalchemy.

If this is not enough there are two special dialects with restricted features:

  • jdbc: can load nearly any jdbc driver
  • dbapi2: can load nearly any dbapi2 driver (python standard), async as well as sync.

Driver installation

You can install the required database drivers with:

Postgres

$ pip install databasez[asyncpg]

MySQL/MariaDB

$ pip install databasez[aiomysql]

or

$ pip install databasez[asyncmy]

SQLite

$ pip install databasez[aiosqlite]

MSSQL

$ pip install databasez[aioodbc]

!!! Note 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: psycopg for PostgreSQL, pymysql for MySQL and pyodbc for SQL Server.


Quickstart

For a simple quickstart example, we will be creating a simple SQLite database to run some queries against.

First, install the required drivers for SQLite and ipython. The ipython is to have an interactive python shell with some extras. IPython also supports await, which is exactly what we need. See more details about it.

Install the required drivers

$ pip install databasez[aiosqlite]
$ pip install ipython

Now from the console, we can run a simple example.

# Create a database instance, and connect to it.
from databasez 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 databasez together with SQLAlchemy core expressions.

Metadata

Release files for databasez 0.13.0

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

Source distribution (sdist)

Source distribution for databasez 0.13.0
File Size Uploaded
databasez-0.13.0.tar.gz 50.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for databasez 0.13.0
File Interpreter ABI Platform
databasez-0.13.0-py3-none-any.whl Python 3 none any Details

Total release size: 114.3 kB

Release files / databasez-0.13.0.tar.gz

Download URL databasez-0.13.0.tar.gz
Size 50.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ecf8f4e32dc3cd9187499a221f262bb194e81e06cb26be0ed835fade7866f937
BLAKE2b-256 checksum
How to use checksums
52c0e18b54ac8f55a59ea166cb0b9cece9fdc464ff6dcbd21aae6d3f25ceeae2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.18.0 {"ci":true,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.12.14"},"installer":{"name":"hatch","version":"1.18.0"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.12.14","system":{"name":"Linux","release":"6.17.0-1022-azure"}} HTTPX2/2.12.0

Release files / databasez-0.13.0-py3-none-any.whl

Download URL databasez-0.13.0-py3-none-any.whl
Size 63.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d20cd3a7ab63c5f8e4a02bedb7c73965babfb56599da987ce533eff723f0ab4
BLAKE2b-256 checksum
How to use checksums
3252c50ea8ff45ee6a2a6e40c29854c810aee629f0653fca8b58bb90aa708568
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.18.0 {"ci":true,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.12.14"},"installer":{"name":"hatch","version":"1.18.0"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.12.14","system":{"name":"Linux","release":"6.17.0-1022-azure"}} HTTPX2/2.12.0

Release history Release notifications | RSS feed

This release

0.13.0 This release

2 release files

0.11.5

2 release files

0.11.4

2 release files

0.10.3

2 release files

0.10.0

2 release files

0.9.7

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

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