Skip to main content

gcm-asyncdb

This library provides better, more robust database API with strong enforcement of transaction logic when working with relational databases.

Currently, only MySQL/MariaDB (aiomysql) is supported, but support for other databases should be easy to implement, when required.

Documentation

API documentation is available at https://gcm-cz.gitlab.io/gcm-asyncdb

Features

  • Fully type-safe, based on modern Python.
  • Fully async.
  • Connection pool with health checking and metrics.
  • Strong transaction usage enforcement, automatic rollback.
  • Advanced result fetching methods to simplify the usage.
  • Observer support for transaction and query events.
  • Structured logging with various loggers for various tasks, per-database logger, correct stack level.
  • Exception hierarchy for correct and easier error handling.
  • Timezone-aware datetimes (with possible fallback to naive datetimes).
  • Native support for sqlfactory statements.
  • OpenTracing and OpenTelemetry support.

Installation

pip install gcm-asyncdb

Extras

  • opentracing - for OpenTracing support
  • opentelemetry - for OpenTelemetry support
  • sqlfactory - for sqlfactory statement support
  • pydantic - for pydantic model support in fetch_object calls.

Usage

from asyncdb.aiomysql import TransactionFactory, MySQLConfig

db = TransactionFactory(MySQLConfig(
    host='localhost',
    user='root',
    database='test'
))


async def main():
    async with db.transaction() as t:
        await t.query('CREATE TABLE test (id INT PRIMARY KEY, name VARCHAR(255))')
        await t.query('INSERT INTO test (id, name) VALUES (1, "test")')
        result = await t.query('SELECT * FROM test')
        async for row in result.fetch_all_dict():
            print(row)

        await t.commit()

License

MIT

Maturity

This library is still very new, but grew from multiple projects where it gradually evolved. So it is already used in production, but it is still recommended to test it thoroughly before using it in production.

Historically, there has been problems with losing connections from connection pool in rare unpredictable error cases, it seems to be resolved now, but there is no regression test for this, so be careful.

Contributing

Feel free to open an issue or a pull request.

Metadata

Release files for gcm-asyncdb 2.4.3

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

Source distribution (sdist)

Source distribution for gcm-asyncdb 2.4.3
File Size Uploaded
gcm_asyncdb-2.4.3.tar.gz 59.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gcm-asyncdb 2.4.3
File Interpreter ABI Platform
gcm_asyncdb-2.4.3-py3-none-any.whl Python 3 none any Details

Total release size: 135.9 kB

Release files / gcm_asyncdb-2.4.3.tar.gz

Download URL gcm_asyncdb-2.4.3.tar.gz
Size 59.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8fc9b6720840e5fed35d44f39c35e43ed7b39c3acfcfbd32906db33cb5066438
BLAKE2b-256 checksum
How to use checksums
6a3c859786cadc4fa57cd0f4d6cae2429b26fa05e17cd09d720a918bc73c3184
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.0 CPython/3.11.14 Linux/6.8.0-90-generic

Release files / gcm_asyncdb-2.4.3-py3-none-any.whl

Download URL gcm_asyncdb-2.4.3-py3-none-any.whl
Size 76.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c8ccae939528a77c74299215d094f1b430666ded023153a2753c8460427ffe6
BLAKE2b-256 checksum
How to use checksums
e06b9061dfb8688b2bbc627fe99b5e920b2c9484fef517ef28bb4dffd88203a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.0 CPython/3.11.14 Linux/6.8.0-90-generic

Release history Release notifications | RSS feed

This release

2.4.3 This release

2 release files

2.4.2

2 release files

2.4.1

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.8

2 release files

2.1.7

2 release files

2.1.6

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.4

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.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