Skip to main content

Read The Docs build Release MIT License Python version support PyPI downloads count GitHub continuous integration

SQLAlchemy 2.0 support for AIOHTTP.

The library provides the next features:

  • initializing asynchronous sessions through a middlewares;

  • initializing asynchronous sessions through a decorators;

  • simple access to one asynchronous session by default key;

  • preventing attributes from being expired after commit by default;

  • support different types of request handlers;

  • support nested applications.

Documentation

https://aiohttp-sqlalchemy.readthedocs.io

Installation

pip install aiohttp-sqlalchemy

Simple example

Install aiosqlite for work with sqlite3:

pip install aiosqlite

Copy and paste this code in a file and run:

from datetime import datetime

import sqlalchemy as sa
from aiohttp import web
from sqlalchemy import orm

import aiohttp_sqlalchemy as ahsa


class Base(orm.DeclarativeBase): ...


class MyModel(Base):
    __tablename__ = "my_table"

    pk = sa.Column(sa.Integer, primary_key=True)
    timestamp = sa.Column(sa.DateTime(), default=datetime.now)


async def main(request):
    sa_session = aiohttp_sqlalchemy.get_session(request)

    async with sa_session.begin():
        sa_session.add(MyModel())
        result = await sa_session.execute(sa.select(MyModel))
        result = result.scalars()

    data = {instance.pk: instance.timestamp.isoformat() for instance in result}
    return web.json_response(data)


async def app_factory():
    app = web.Application()

    aiohttp_sqlalchemy.setup(
        app,
        [
            aiohttp_sqlalchemy.bind("sqlite+aiosqlite:///"),
        ],
    )
    await aiohttp_sqlalchemy.init_db(app, Base.metadata)

    app.add_routes([web.get("/", main)])
    return app


if __name__ == "__main__":
    web.run_app(app_factory(), port=8087)

Release files for aiohttp-sqlalchemy 1.2.0

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

Source distribution (sdist)

Source distribution for aiohttp-sqlalchemy 1.2.0
File Size Uploaded
aiohttp_sqlalchemy-1.2.0.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aiohttp-sqlalchemy 1.2.0
File Interpreter ABI Platform
aiohttp_sqlalchemy-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.7 kB

Release files / aiohttp_sqlalchemy-1.2.0.tar.gz

Download URL aiohttp_sqlalchemy-1.2.0.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
37e812728a25d0e509e2ffec5382ca948e2c2b361aa17340939a46684b9231cc
BLAKE2b-256 checksum
How to use checksums
80396ac244be2a9246974a224aaaf38a01def4ef34b8f1f005b17d4724c51ead
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.3 Linux/6.8.0-90-generic

Release files / aiohttp_sqlalchemy-1.2.0-py3-none-any.whl

Download URL aiohttp_sqlalchemy-1.2.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
219b66cc3c11f1d1e6eb61fd2cdefd8ed7172a79cf856cbd5f7bb586dd3b5326
BLAKE2b-256 checksum
How to use checksums
2fad5e2dbb7b543629db752ffe10f2b0ae41f994484b55fc5c0eee4271bc3344
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.3 Linux/6.8.0-90-generic

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.35.0

2 release files

0.33.0

2 release files

0.32.1

2 release files

0.32.0

2 release files

0.31.0

2 release files

0.30.2

2 release files

0.30.1

2 release files

0.30.0

2 release files

0.29.0

2 release files

0.28.0

2 release files

0.27.0

2 release files

0.26.0

2 release files

0.25.0

2 release files

0.24.0

2 release files

0.23.0

2 release files

0.22.0

2 release files

0.18.1

2 release files

0.18.0

2 release files

0.17.4

2 release files

0.17.3

2 release files

0.17.2

2 release files

0.17.1

2 release files

0.17.0

2 release files

0.16.1

2 release files

0.16.0

2 release files

0.15.5

2 release files

0.15.4

2 release files

0.15.3

2 release files

0.15.2

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.14.1

2 release files

0.14.0

2 release files

0.13.2

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.1.1

2 release files

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