Async Support for various databases
Project description
AIO-Databases
The package gives you asycio support for a range of databases (SQLite, PostgreSQL, MySQL).
Requirements
- python >= 3.7
Installation
aio-databases should be installed using pip:
$ pip install aio-databases
You have to choose and install the required database drivers with:
# To support SQLite
$ pip install aio-databases[aiosqlite]
# To support MySQL
$ pip install aio-databases[aiomysql]
# To support PostgreSQL (choose one)
$ pip install aio-databases[aiopg]
$ pip install aio-databases[asyncpg]
Usage
- Init a database
from aio_databases import Database
db = Database('sqlite:///:memory:')
- Prepare the database to work
async def my_app_starts():
# Initialize a database's pool
await db.connect()
async def my_app_ends():
# Close pool/connections
await db.disconnect()
# As an alternative users are able to use the database
# as an async context manager
async with db:
await my_main_coroutine()
- Run SQL queries
await db.execute('select $1', '1')
await db.executemany('select $1', '1', '2', '3')
records = await db.fetchall('select (2 * $1) res', 2)
assert records == [(4,)]
record = await db.fetchone('select (2 * $1) res', 2)
assert record == (4,)
assert record['res'] == 4
result = await db.fetchval('select 2 * $1', 2)
assert result == 4
- Use transactions
async with db.transaction() as trans1:
# do some work ...
async with db.transaction() as trans2:
# do some work ...
await trans2.rollback()
Bug tracker
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/aio-databases/issues
Contributing
Development of the project happens at: https://github.com/klen/aio-databases
License
Licensed under a MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aio-databases-0.0.18.tar.gz
(8.0 kB
view details)
Built Distribution
File details
Details for the file aio-databases-0.0.18.tar.gz
.
File metadata
- Download URL: aio-databases-0.0.18.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 938f078bf5aa7258f43e1262448e72292e0bfb2b5bffaea00ff366becc8da590 |
|
MD5 | 1521b585dc933b9442b12f7da987b241 |
|
BLAKE2b-256 | c510eff33c8efac45ec1bae29872c4ad4c7e4fabbaa2114bf01d9d3d6359b317 |
File details
Details for the file aio_databases-0.0.18-py3-none-any.whl
.
File metadata
- Download URL: aio_databases-0.0.18-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68f388daa09280eb27b310beb9e7c92931a81f5b3268bc2abe3b0cc2320f4d17 |
|
MD5 | 0c90b4ae8b5f1010f67a55c634087c3f |
|
BLAKE2b-256 | 49e5c99838fdae96967a22c05c6c8e58c224db3dfdb75bdcb44f2a4ac949c205 |