{"id":33609393,"url":"https://github.com/krylosov-aa/context-async-sqlalchemy","last_synced_at":"2026-04-08T13:31:47.434Z","repository":{"id":323377526,"uuid":"1092714600","full_name":"krylosov-aa/context-async-sqlalchemy","owner":"krylosov-aa","description":"A convenient way to configure and work with an async SQLAlchemy session through context in asynchronous applications","archived":false,"fork":false,"pushed_at":"2026-01-12T21:32:15.000Z","size":3585,"stargazers_count":54,"open_issues_count":6,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-13T01:46:40.336Z","etag":null,"topics":["asgi","asgi-middleware","async","asynchronous","asyncio","context","contextvars","fastapi","fastapi-boilerplate","fastapi-sqlalchemy","ioc","ioc-container","python","python3","sql","sqlalchemy","sqlalchemy-async","sqlalchemy-python","sqlalchemy2","starlette"],"latest_commit_sha":null,"homepage":"https://krylosov-aa.github.io/context-async-sqlalchemy/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krylosov-aa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-09T06:40:13.000Z","updated_at":"2026-01-12T21:32:19.000Z","dependencies_parsed_at":"2025-11-30T00:03:43.163Z","dependency_job_id":null,"html_url":"https://github.com/krylosov-aa/context-async-sqlalchemy","commit_stats":null,"previous_names":["krylosov-aa/context-async-sqlalchemy"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/krylosov-aa/context-async-sqlalchemy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krylosov-aa%2Fcontext-async-sqlalchemy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krylosov-aa%2Fcontext-async-sqlalchemy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krylosov-aa%2Fcontext-async-sqlalchemy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krylosov-aa%2Fcontext-async-sqlalchemy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krylosov-aa","download_url":"https://codeload.github.com/krylosov-aa/context-async-sqlalchemy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krylosov-aa%2Fcontext-async-sqlalchemy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31558380,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T10:21:54.569Z","status":"ssl_error","status_checked_at":"2026-04-08T10:21:38.171Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asgi","asgi-middleware","async","asynchronous","asyncio","context","contextvars","fastapi","fastapi-boilerplate","fastapi-sqlalchemy","ioc","ioc-container","python","python3","sql","sqlalchemy","sqlalchemy-async","sqlalchemy-python","sqlalchemy2","starlette"],"created_at":"2025-11-30T19:02:50.348Z","updated_at":"2026-04-08T13:31:47.424Z","avatar_url":"https://github.com/krylosov-aa.png","language":"Python","readme":"# context-async-sqlalchemy\n\n[![PyPI](https://img.shields.io/pypi/v/context-async-sqlalchemy.svg)](https://pypi.org/project/context-async-sqlalchemy/)\n[![PyPI Downloads](https://static.pepy.tech/personalized-badge/context-async-sqlalchemy?period=total\u0026units=INTERNATIONAL_SYSTEM\u0026left_color=BLACK\u0026right_color=GREEN\u0026left_text=downloads)](https://pepy.tech/projects/context-async-sqlalchemy)\n[![Tests](https://github.com/krylosov-aa/context-async-sqlalchemy/actions/workflows/tests.yml/badge.svg)](https://github.com/krylosov-aa/context-async-sqlalchemy/actions/workflows/tests.yml) (coverage \u003e 90%)\n\n\n[DOCUMENTATION](https://krylosov-aa.github.io/context-async-sqlalchemy/)\n\nProvides a super convenient way to work with SQLAlchemy in asynchronous\napplications.\nIt handles the lifecycle management of the engine, sessions, and\ntransactions.\n\nThe main goal is to provide quick and easy access to a session,\nwithout worrying about opening or closing it when it’s not necessary.\n\nKey features:\n\n- Automatically manages the lifecycle of the engine, sessions, and\ntransactions\n- Allows for user autonomy when manually opening or closing sessions and\ntransactions\n- Framework-agnostic\n- Not a wrapper around SQLAlchemy\n- Convenient for testing\n- Runtime host switching\n- Supports multiple databases and sessions per database\n- Provides tools for running concurrent SQL queries\n- Fully lazy initialization\n\n\n## Example of a typical session\n\n```python\nfrom context_async_sqlalchemy import db_session\nfrom sqlalchemy import insert\n\nfrom database import connection  # your configured connection to the database\nfrom models import ExampleTable  # a model for example\n\nasync def some_func() -\u003e None:\n    # Creates a session with no connection to the database yet\n    session = await db_session(connection)\n    \n    stmt = insert(ExampleTable).values(text=\"example_with_db_session\")\n\n    # A connection and transaction open in the first request.\n    await session.execute(stmt)\n    \n    # If you call db_session again, it returns the same session\n    # even in child coroutines.\n    session = await db_session(connection)\n    \n    # The second request uses the same connection and the same transaction\n    await session.execute(stmt)\n\n    # The commit and closing of the session occurs automatically\n```\n\n## How it works\n\n![basic schema.png](https://github.com/krylosov-aa/context-async-sqlalchemy/blob/main/docs_sources/docs/img/basic_schema.png?raw=true)\n\n1. Before executing your code, the middleware prepares a container in\nwhich the sessions required by your code are stored.\nThe container is saved in `contextvars`.\n2. Your code accesses the library to create new sessions and retrieve\nexisting ones.\n3. The middleware automatically commits or rolls back open\ntransactions. It also closes open sessions and clears the context.\n\nThe library provides the ability to commit, roll back, and close at any","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrylosov-aa%2Fcontext-async-sqlalchemy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrylosov-aa%2Fcontext-async-sqlalchemy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrylosov-aa%2Fcontext-async-sqlalchemy/lists"}