CodeVetter · Repo Unpack · System map
encode/starlette
The runtime contract is ASGI: a server supplies a mutable scope and asynchronous receive/send channels. Starlette composes a router and middleware, while individual components can also act as ASGI applications. State is held in application or connection mappings, upload temporary files, and signed client cookies; database selection belongs to consuming applications. Packaging and documentation deployment are separate from serving developer applications.
- ASGIApp is Callable[[Scope, Receive, Send], Awaitable[None]]; users instantiate Starlette and supply an external ASGI server, illustrated by uvicorn main:app.
- Starlette.__call__ sets scope['app'] and lazily caches a stack ordered as ServerErrorMiddleware, optional RequestBodyLimitMiddleware, user middleware, ExceptionMiddleware, then Router.
- Router.app handles HTTP, WebSocket, and lifespan scopes; Route, WebSocketRoute, Mount, and Host provide endpoint adaptation, subapplication composition, and host-based dispatch.
- Synchronous endpoints and background callbacks cross into AnyIO worker threads through run_in_threadpool; synchronous streaming iterators use iterate_in_threadpool.
- State wraps an in-memory dictionary, multipart uploads use SpooledTemporaryFile, and SessionMiddleware stores signed JSON in cookies; documentation leaves database implementation to the consuming application.
- The package requires Python >=3.11, anyio>=4,<5, and conditional typing_extensions; the full extra adds itsdangerous, Jinja2, OpenTelemetry API, python-multipart, PyYAML, httpx, and httpx2.
- Hatchling builds the distribution using the version in starlette/__init__.py; scripts/install uses uv sync --frozen, scripts/check runs version consistency, Ruff and mypy checks, and scripts/build runs uv build, Twine, and Zensical.
- Publish CI builds package and documentation artifacts, publishes PyPI only for tags, and deploys documentation to GitHub Pages and Cloudflare; wrangler.toml points Cloudflare assets at ./site.