FastAPI vs Starlette: What’s the Difference
FastAPI is built directly on Starlette, so this isn’t really a competition — here’s what FastAPI actually adds on top, and when Starlette alone is enough
For a typical REST API, FastAPI is the right choice — its validation and auto-docs are worth the small overhead over using Starlette directly. This one isn’t a real rivalry — FastAPI is built directly on top of Starlette, using it for the ASGI plumbing underneath. The actual question is what FastAPI adds, and whether you need it.
What Starlette gives you
Starlette is a lightweight ASGI toolkit — routing, middleware, WebSockets, background tasks, and the core request/response objects that power async Python web frameworks. It’s minimal by design: no built-in data validation, no automatic docs, no opinion about how your data should be shaped. That minimalism is the point — Starlette is meant to be a foundation other frameworks (or your own code) build on directly.
What FastAPI adds on top
FastAPI takes Starlette’s ASGI layer and adds the pieces most API projects actually want: request and response validation via Pydantic models, automatic interactive API docs (Swagger UI / ReDoc) generated from your type hints, and a dependency-injection system for shared logic like auth checks. None of this replaces Starlette — it wraps it, and Starlette’s own objects and middleware are still directly usable inside a FastAPI app.
Performance: close, not the deciding factor
FastAPI does more work per request — validating incoming data and serializing responses against Pydantic models — so it carries some overhead Starlette alone doesn’t have. In practice this rarely matters: database queries, external API calls, and I/O dominate real-world request time far more than this validation overhead does.
When to choose Starlette directly
Reach for Starlette without FastAPI when you don’t need automatic validation or docs and want the thinnest possible ASGI layer — a WebSocket-heavy service, a very high-throughput internal API where every microsecond of routing overhead matters, or when you’re building your own opinionated framework on top rather than adopting FastAPI’s conventions.
Keep Starlette patched
FastAPI is built on Starlette, so a Starlette flaw is a flaw in your FastAPI app. The one to know about is CVE-2026-48710 (GHSA-86qp-5c8j-p5mr, rated medium, CVSS 6.5). In Starlette 1.0.0 and earlier, request.url was rebuilt from the HTTP Host header without validating it. Routing uses the real request path, so a malformed Host header (one containing /, ? or #) could make request.url.path differ from the path that was actually served. Middleware or endpoints that make security decisions from request.url.path, typically blocking access to a path prefix, could be bypassed. The advisory describes checks based on request.url “rather than the raw scope path” as the affected pattern.
Starlette 1.0.1 (21 May 2026) validates the header. CISA added the vulnerability to its Known Exploited Vulnerabilities catalogue on 2 September 2026, which is evidence that it has been exploited in the wild. The advisory adds that a proxy or load balancer only protects you if it rejects or normalises the malformed header before forwarding it.
Two practical points:
- FastAPI does not force a patched Starlette. FastAPI 0.162.0 requires only
starlette>=0.46.0. A fresh install resolves to a recent Starlette (1.10.0 on 7 November 2026), but an older virtual environment, lockfile or container image can still hold 1.0.0 or earlier. Check withpython -m pip show starlettein each environment and upgrade to 1.0.1 or later, then rebuild any image that pinned the old version. - Look at how you check permissions. If your own code authorises requests by reading
request.url.path, that is the pattern the advisory warns about, and it is worth reviewing even on a patched version.
For how to catch issues like this routinely, see Python dependency security.
The practical default
For a typical REST API, FastAPI’s validation and auto-docs are worth the small overhead — they eliminate a whole category of manual request-parsing bugs and give you working API documentation for free. Choose Starlette directly only when you have a specific reason not to want what FastAPI adds.
Frequently Asked Questions
Is FastAPI built on Starlette?
Yes — FastAPI uses Starlette directly for the underlying ASGI toolkit (routing, middleware, WebSockets, background tasks) and adds request/response validation, automatic OpenAPI docs, and dependency injection on top, using Pydantic.
Is FastAPI slower than Starlette?
Marginally, in raw routing overhead, because it does more per request — validating request/response data against Pydantic models. For most applications this difference is not what determines real-world performance; database and I/O calls dominate first.
When should you use Starlette instead of FastAPI?
When you don’t need request/response schema validation or auto-generated docs and want the lightest possible ASGI layer — a lower-level service, a WebSocket-heavy app, or when you’re building your own framework-like abstraction on top.
Can you use Starlette features directly inside a FastAPI app?
Yes — since FastAPI is built on Starlette, its middleware, background tasks, and lower-level request/response objects are all available and commonly used directly inside FastAPI applications when needed.
Does the Starlette vulnerability CVE-2026-48710 affect FastAPI?
It can. FastAPI is built on Starlette, and Starlette 1.0.0 and earlier rebuilt request.url from an unvalidated Host header, so a malformed header could make request.url.path differ from the path the router used and bypass checks that rely on it. Starlette 1.0.1 fixed it, but FastAPI 0.162.0 only requires starlette>=0.46.0, so check which Starlette your environment actually has and upgrade to 1.0.1 or later. CISA lists the flaw in its Known Exploited Vulnerabilities catalogue.