Skip to main content

A thin async wrapper for SQLAlchemy sessions.

Project description

AsyncAlchemy

A thin async wrapper for SQLAlchemy sessions.

Besides being async, the wrapper manages the context of the session for the execution block.Commits incoming changes if successfull or rolls back changes if an exceptions occurs.
Note: The upcoming SQLAlchemy 1.4 version will include built-in async functionality, it's recommended to upgrade to it once it's released.

Install

Pip

pip install asyncalchemy

From Source

The project uses poetry for dependency management and packaging.
To run from source clone project and:

pip install poetry
poetry install

Usage

Basic Example

from asyncalchemy import create_session_factory

# Create AsyncAlchemy session factory
session_factory = create_session_factory(db_uri, Base)

# Create session
async with session_factory() as session:
    await session.query(Something).filter_by(something="else")

Example With Extra Params

from sqlalchemy.pool import NullPool

from asyncalchemy import create_session_factory

# Create session factory with additional SQLAlchemy params
session_factory = create_session_factory(db_uri, Base, poolclass=NullPool)

# Create session
async with session_factory() as session:
    await second_session.add(Something)
    await second_session.flush()

    # Reuse session
    async with session_factory(reuse_session=session) as second_session:
        await session.delete(Something)

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

asyncalchemy-1.1.4.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

asyncalchemy-1.1.4-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file asyncalchemy-1.1.4.tar.gz.

File metadata

  • Download URL: asyncalchemy-1.1.4.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.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 asyncalchemy-1.1.4.tar.gz
Algorithm Hash digest
SHA256 b1e6a8493954e5bbf7a4e6cc603975e13b87424b412c57d00641be52dbec8236
MD5 681d3d54869d909c8276d1a94e196997
BLAKE2b-256 4a847e5388040577ff21a618bb8622aeddc825e445c7f0a2de8f899e7159eb76

See more details on using hashes here.

File details

Details for the file asyncalchemy-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: asyncalchemy-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.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 asyncalchemy-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4d56fa01b8a351d74b7074188783e2fd06f3457e14c0d30655fb39060d758c1c
MD5 154bb515460786fa81f006d16df8651e
BLAKE2b-256 d202027dbe49d587cf89c0f77fa5e7b2bc91ed5efa8536d3148f47c490a7620f

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