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

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.5
File Size Uploaded Provenance Actions
gcm_asyncdb-2.4.5.tar.gz 60.5 kB Without provenance Details for gcm_asyncdb-2.4.5.tar.gz

Built distribution (wheel)

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

Total release size: 137.9 kB

Release files / gcm_asyncdb-2.4.5.tar.gz

Download URL gcm_asyncdb-2.4.5.tar.gz
Size 60.5 kB
Tags Source
SHA-256 checksum
How to use checksums
86f6d415a4fa6f2d19cc35dc1e2aae4d9437cd2b48c10225bf34be270eafe44b
BLAKE2b-256 checksum
How to use checksums
684c3ca0b643f7a51622f455017522d60102c4e81fda44786fc0281c67563630
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.11.15 Linux/6.8.0-138-generic

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

Download URL gcm_asyncdb-2.4.5-py3-none-any.whl
Size 77.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3e3c33be2601c2044e15abc13ac443e6965397276a14594eee039d104b9fdbe
BLAKE2b-256 checksum
How to use checksums
5fe5380687c7e683146d5cb0fa861e1a3e7675f1e860a0f3ba6c01003162e46d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.11.15 Linux/6.8.0-138-generic

Security for gcm-asyncdb 2.4.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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