| Name | Modified | Size | Downloads / Week |
|---|---|---|---|
| Parent folder | |||
| README.md | 2026-01-18 | 1.1 kB | |
| Version 0.52.0 source code.tar.gz | 2026-01-18 | 2.7 MB | |
| Version 0.52.0 source code.zip | 2026-01-18 | 2.7 MB | |
| Totals: 3 Items | 5.4 MB | 0 | |
In this release, State can be accessed using dictionary-style syntax for improved type safety (#3036).
:::python
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from typing import TypedDict
import httpx
from starlette.applications import Starlette
from starlette.requests import Request
class State(TypedDict):
http_client: httpx.AsyncClient
@asynccontextmanager
async def lifespan(app: Starlette) -> AsyncIterator[State]:
async with httpx.AsyncClient() as client:
yield {"http_client": client}
async def homepage(request: Request[State]):
client = request.state["http_client"]
# If you run the below line with mypy or pyright, it will reveal the correct type.
reveal_type(client) # Revealed type is 'httpx.AsyncClient'
See Accessing State for more details.
Full Changelog: https://github.com/Kludex/starlette/compare/0.51.0...0.52.0