Skip to main content

Async database support for Python.

Project description

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.

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

databasez-0.12.0.tar.gz (49.3 kB view details)

Uploaded Source

Built Distribution

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

databasez-0.12.0-py3-none-any.whl (62.9 kB view details)

Uploaded Python 3

File details

Details for the file databasez-0.12.0.tar.gz.

File metadata

  • Download URL: databasez-0.12.0.tar.gz
  • Upload date:
  • Size: 49.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.12.12 HTTPX/0.28.1

File hashes

Hashes for databasez-0.12.0.tar.gz
Algorithm Hash digest
SHA256 81709a80eee4506c845bbfc7296a825fc8d479cdbfada65ed5c4161a35566504
MD5 102e5b4546eb4c4e48d0c8a052bbd65b
BLAKE2b-256 964522100f4b83211d57363e58cd632b1d40166e0bf007cd7a722a955ac215d4

See more details on using hashes here.

File details

Details for the file databasez-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: databasez-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 62.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.12.12 HTTPX/0.28.1

File hashes

Hashes for databasez-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b7f12d3492e9645fa8b69f29732d8435cb2cdaba8244552f138dadb311fc90f
MD5 a87d1c66e071778d0376233e117f89d5
BLAKE2b-256 37f0203538ccd037d01175adec9fc4c3a2b13f38ded3f9680e4ba3b4717c9323

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