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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asyncalchemy-1.1.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: asyncalchemy-1.1.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for asyncalchemy-1.1.1.tar.gz
Algorithm Hash digest
SHA256 bd62cb2e02af27db5940b9dfb22877d3384165caba1b25bc11e5710489a8e802
MD5 5a01404e87479074716ccd6a6256db45
BLAKE2b-256 42b69779e6a67ce3ef0b466ef182e80b64ed42b6174560d00b411f30a9ced4d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asyncalchemy-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for asyncalchemy-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 276010d5bb9c66ddcb831b8e4caa8d2414b439d9383e3c7d566b8697475087e3
MD5 0c8587f41a5cd3d9c43d025ab9aabbd7
BLAKE2b-256 d4ce1082d0361b684c01854c6c49a0fc46ab0ac52a6ba4dd46836c293bb57104

See more details on using hashes here.

Supported by

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