# asgi-sqlalchemy
ASGI Middleware that manages the lifespan of a database engine and a corresponding session.
## Usage:
### FastAPI:
```python
from contextlib import AsyncContextManager
from collections.abc import AsyncGenerator
from typing_extensions import TypedDict
from fastapi import FastAPI
from asgi_sqlalchemy import DatabaseContext, SessionMiddleware
from asgi_sqlalchemy.fastapi import SessionDependency
class AppState(TypedDict):
db: DatabaseContext
async def lifespan() -> AsyncGenerator[AppState]:
async with DatabaseContext(...) as db:
yield {"db": db}
app = FastAPI()
app.add_middleware(SessionMiddleware)
@app.get("/db")
async def handler(session: SessionDependency) -> str:
# do something with your async session!
```
Raw data
{
"_id": null,
"home_page": null,
"name": "asgi-sqlalchemy",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "FastAPI, Middleware, SQLAlchemy, asgi",
"author": null,
"author_email": "Abhi Agarwal <abhiaagarwal01@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/cb/b2/b9a59608971b7fca27a2bebc480be73dbd7916127c2eecd3b8ea3d7c343f/asgi_sqlalchemy-0.1.1.tar.gz",
"platform": null,
"description": "# asgi-sqlalchemy\n\nASGI Middleware that manages the lifespan of a database engine and a corresponding session.\n\n## Usage:\n\n### FastAPI:\n\n```python\nfrom contextlib import AsyncContextManager\nfrom collections.abc import AsyncGenerator\nfrom typing_extensions import TypedDict\n\nfrom fastapi import FastAPI\n\nfrom asgi_sqlalchemy import DatabaseContext, SessionMiddleware\nfrom asgi_sqlalchemy.fastapi import SessionDependency\n\nclass AppState(TypedDict):\n db: DatabaseContext\n\nasync def lifespan() -> AsyncGenerator[AppState]:\n async with DatabaseContext(...) as db:\n yield {\"db\": db}\n\napp = FastAPI()\napp.add_middleware(SessionMiddleware)\n\n@app.get(\"/db\")\nasync def handler(session: SessionDependency) -> str:\n # do something with your async session!\n```",
"bugtrack_url": null,
"license": null,
"summary": "Pure ASGI Database middleware.",
"version": "0.1.1",
"project_urls": {
"homepage": "https://github.com/abhiaagarwal/asgi-sqlalchemy",
"issues": "https://github.com/abhiaagarwal/asgi-sqlalchemy/issues",
"repository": "https://github.com/abhiaagarwal/asgi-sqlalchemy"
},
"split_keywords": [
"fastapi",
" middleware",
" sqlalchemy",
" asgi"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "5ee4a85a0b5d583467429985819336ed068b0273ab8090f3df407bb43008cc3e",
"md5": "d89d69ccb4f9d3e9738edef62dd1fa81",
"sha256": "dbb848defe5d6e47fea155079d000d7212d6fcd5a4af239a80da18e0318ede9e"
},
"downloads": -1,
"filename": "asgi_sqlalchemy-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d89d69ccb4f9d3e9738edef62dd1fa81",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 4952,
"upload_time": "2025-09-07T20:22:59",
"upload_time_iso_8601": "2025-09-07T20:22:59.333957Z",
"url": "https://files.pythonhosted.org/packages/5e/e4/a85a0b5d583467429985819336ed068b0273ab8090f3df407bb43008cc3e/asgi_sqlalchemy-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "cbb2b9a59608971b7fca27a2bebc480be73dbd7916127c2eecd3b8ea3d7c343f",
"md5": "450f937c5a54d6c9183e44452ab8329b",
"sha256": "ecb06b461674d6ebbd2ad3dc0838a79717452667ea384e8fc54072f0b585958d"
},
"downloads": -1,
"filename": "asgi_sqlalchemy-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "450f937c5a54d6c9183e44452ab8329b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 68000,
"upload_time": "2025-09-07T20:23:00",
"upload_time_iso_8601": "2025-09-07T20:23:00.139621Z",
"url": "https://files.pythonhosted.org/packages/cb/b2/b9a59608971b7fca27a2bebc480be73dbd7916127c2eecd3b8ea3d7c343f/asgi_sqlalchemy-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-07 20:23:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "abhiaagarwal",
"github_project": "asgi-sqlalchemy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "asgi-sqlalchemy"
}