Metadata-Version: 2.4
Name: asgi-sqlalchemy
Version: 0.1.1
Summary: Pure ASGI Database middleware.
Project-URL: homepage, https://github.com/abhiaagarwal/asgi-sqlalchemy
Project-URL: repository, https://github.com/abhiaagarwal/asgi-sqlalchemy
Project-URL: issues, https://github.com/abhiaagarwal/asgi-sqlalchemy/issues
Author-email: Abhi Agarwal <abhiaagarwal01@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: FastAPI,Middleware,SQLAlchemy,asgi
Classifier: Framework :: FastAPI
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Requires-Dist: sqlalchemy>=2
Requires-Dist: typing-extensions>=4
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.106; extra == 'fastapi'
Provides-Extra: type-hints
Requires-Dist: asgiref>=3.8.1; extra == 'type-hints'
Description-Content-Type: text/markdown

# 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!
```