Registry / web-framework / starlette

starlette

JSON →
library1.6.0pypypi✓ verified 26d ago

Lightweight ASGI framework and toolkit. Foundation for FastAPI. Released version 1.0.0 on Mar 22, 2026 — first stable release after 8 years on ZeroVer (0.x). Now follows SemVer. 1.0 removed all features deprecated during the 0.x era. Directly used by the Python MCP SDK.

pip install starlette
INSTALL
IMPORT
SIG · STARLETTE
S
starlette
web-frameworkpythonv1.6.0
Install
2.7s avg
Import
Disk
27MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 27.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.7s · import 0.000s · 29MB
27MB installed
● package 27MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lifespan
from contextlib import asynccontextmanager from starlette.applications import Starlette @asynccontextmanager async def lifespan(app): # startup yield # shutdown app = Starlette(lifespan=lifespan)
app = Starlette( on_startup=[startup_handler], on_shutdown=[shutdown_handler] ) # on_startup/on_shutdown removed in 1.0
on_startup and on_shutdown parameters removed in 1.0. The lifespan context manager is the only supported pattern.
Route (declarative)
from starlette.applications import Starlette from starlette.routing import Route async def homepage(request): ... app = Starlette(routes=[Route('/', homepage)])
@app.route('/') async def homepage(request): ... # @app.route() decorator removed in 1.0
@app.route() and @app.websocket_route() decorators removed in 1.0. Use declarative Route() objects in the routes list.

Minimal Starlette 1.0 app with lifespan and declarative routing.

from contextlib import asynccontextmanager from starlette.applications import Starlette from starlette.requests import Request from starlette.responses import JSONResponse from starlette.routing import Route @asynccontextmanager async def lifespan(app): # startup logic yield # shutdown logic async def homepage(request: Request): return JSONResponse({'hello': 'world'}) app = Starlette( routes=[Route('/', homepage)], lifespan=lifespan, ) # Run: uvicorn main:app
Debug
Known issues
breakingon_startup= and on_shutdown= parameters removed in 1.0. add_event_handler() also removed. All three were the primary patterns in older tutorials and LLM-generated code.
fix
Use lifespan context manager: @asynccontextmanager async def lifespan(app): yield — pass as app = Starlette(lifespan=lifespan).
affects: >= 1.0.0
breaking@app.route() and @app.websocket_route() decorators removed in 1.0. Were deprecated since 0.23.0 but widely used in tutorials for years.
fix
Use declarative routing: Starlette(routes=[Route('/', handler), WebSocketRoute('/ws', ws_handler)]).
affects: >= 1.0.0
breakingJinja2Templates now raises ImportError at import time if jinja2 is not installed. Previously only raised when instantiating the class.
fix
pip install jinja2 or pip install 'starlette[full]'
affects: >= 1.0.0
breakingJinja2Templates now enables autoescape by default. Templates that relied on unescaped output (e.g. rendering HTML strings) will now escape them.
fix
Mark trusted HTML strings with Markup() from markupsafe, or pass autoescape=False to Jinja2Templates() to restore old behavior.
affects: >= 1.0.0
breakingTestClient now uses httpx instead of requests (changed in 0.20.0). Test suites using requests-specific APIs on TestClient responses will break.
fix
pip install httpx. Use httpx response API — most methods are compatible. Use the bump-testclient migration tool for larger test suites.
affects: >= 0.20.0
breakingPython 3.8 and 3.9 support dropped. Starlette 1.0 requires Python >=3.10.
fix
Upgrade Python to 3.10+. Pin starlette<1.0 to remain on Python 3.8/3.9.
affects: >= 1.0.0
gotchaStarlette is typically a transitive dependency via FastAPI — do not pin starlette version directly. FastAPI manages its own compatible Starlette range. Pinning starlette independently can cause conflicts.
fix
Let FastAPI manage the starlette version. Only pin starlette directly if using it standalone without FastAPI.
affects: all
Upgrade
Version history
1.6.0latest on PyPI · released Aug 8, 2026
Audit
Dependencies
anyio>=3.4.0,<5requiredAsync runtime abstraction. Required, installed automatically.
jinja2optionalRequired for Jinja2Templates. NOT auto-installed. Import now fails at import time if missing (changed in 1.0).
python-multipart>=0.0.7optionalRequired for form data and file uploads.
httpxoptionalRequired for TestClient. Replaced requests in 0.20.0.
itsdangerousoptionalRequired for SessionMiddleware.
Agent activity
9 hits · last 30 days
node
6
OpenAI (training)
1
Resources
starlette — pip install starlette · libregistry