Skip to main content

Async Support for various databases

Project description

AIO-Databases

The package gives you asycio support for a range of databases (SQLite, PostgreSQL, MySQL).

Tests Status PYPI Version Python Versions

Requirements

  • python >= 3.7

Installation

aio-databases should be installed using pip:

$ pip install aio-databases

You can install the required database drivers with:

$ pip install aio-databases[sqlite]
$ pip install aio-databases[postgresql]
$ pip install aio-databases[mysql]

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


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.15.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

aio_databases-0.0.15-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file aio-databases-0.0.15.tar.gz.

File metadata

  • Download URL: aio-databases-0.0.15.tar.gz
  • Upload date:
  • Size: 7.6 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

Hashes for aio-databases-0.0.15.tar.gz
Algorithm Hash digest
SHA256 f0d317134fa77239f70f023000a946d5c3a726a314d30fc440b6a982c2244e75
MD5 fd9acef5890552a4008b4b6549466fa4
BLAKE2b-256 815b3ae3630ecabde3c57f2ff0f1b01a303bce85e63fba2906bb7f518939e321

See more details on using hashes here.

File details

Details for the file aio_databases-0.0.15-py3-none-any.whl.

File metadata

  • Download URL: aio_databases-0.0.15-py3-none-any.whl
  • Upload date:
  • Size: 8.5 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

Hashes for aio_databases-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 52040bf66ae8e577301c60d4d866310914ccd19778bbf7f0345a7602afeb6413
MD5 5cba8df73f04ba1d32ed5e15e7e04ea9
BLAKE2b-256 c68dac41664656f6bf5e7f8d9bc60bd468b4b2ba3cde0cba2563ffe799834a1c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page