Repository navigation
Releases
Version 1.10.0
π Leaner URL-encoded form parsing
Starlette 1.10.0 parses URL-encoded forms with less memory and CPU, no longer drops the last field when a stream ends early, and lets you compare FormData that holds several uploads under one key.
uv pip install starlette==1.10.0- Forms with many fields parse faster and use less memory (#3724).
FormParserbuilds each field in the parser callbacks instead of queueing every event and replaying it. On CodSpeed, 1000 fields went from 42.8 ms to 34.9 ms and from 63.5 KB to 54.5 KB, and themax_fieldslimit case went from 6,880 B to 864 B. - The last field is kept when the request stream ends without an empty chunk (#3599). The parser is now finalized once the stream is exhausted, so custom streams that never yield a final
b""no longer lose their last field. FormDatawith repeated uploads can be compared (#3619). Comparing twoFormDataobjects with severalUploadFilevalues under the same key used to raiseTypeError.
β οΈ Behaviour changes
- Multidict equality keeps the order of values under a repeated key (#3619). Keys can still appear in any order, but
QueryParams("a=1&a=2")andQueryParams("a=2&a=1")are no longer equal, matching whatgetlist()returns. starlette.formparsers.FormMessageis deprecated (#3724). The parser no longer uses it, andFormParser.messagesis gone. CallingFormMessage(...)emits aStarletteDeprecationWarning.
π§ Routing and URL generation
- Path parameter values that look like a placeholder are kept as they are (#3725).
url_path_for("route", category="{id}", id="42")on/{category}/{id}now returns/{id}/42instead of/42/42. Substitution also got faster, from 549 ns to 520 ns with two parameters and from 1,078 ns to 779 ns with five. - Route matching does less work per request (#3665, #3722).
Matchmembers are compared by identity, cutting up to 4.9% of the instructions per dispatch in the routing benchmarks. WSGIMiddlewarestripsroot_pathonly at a path segment boundary (#3718). A request to/applicationunder aroot_pathof/appno longer becomes/lication.FloatConvertorreports NaN and infinity correctly (#3716). NaN was reported as a negative float.
π‘οΈ Middleware, responses and config
- Handled exceptions no longer keep requests alive (#3205). Starlette clears the traceback after an exception handler runs, so an exception instance reused across requests, such as a module-level
HTTPException, no longer pins per-request objects in memory. - Middlewares accept
http.response.startwithoutheaders(#3721).BaseHTTPMiddleware,GZipMiddlewareandSessionMiddlewaredefault the omitted field to an empty list instead of raisingKeyError. FileResponseignoresRangeon methods other thanGETandHEAD(#3679). APOSTendpoint that returns a file now sends the full file, as RFC 9110 requires.Configstrips one pair of matching outer quotes from env file values (#3720).KEY='say "hi"'now reads assay "hi"instead ofsay "hi.
Full changelog: 1.9.0...1.10.0
Version 1.9.0
This release streams TestClient response bodies, so client.stream() returns before the application finishes. It also escapes path delimiters when building URLs, matches host names case-insensitively, and keeps every existing Vary header.
Changed
- Stream
TestClientresponse bodies, soclient.stream()returns before the application finishes. Closing an unfinished streamed response now cancels the application #3491.
Fixed
- Percent-encode
?,#,\and a leading//in the request path when buildingrequest.url, and\and a leading//inurl_path_for#3671. - Use the byte length for
Content-Lengthwhen the response body is a typed or multidimensionalmemoryview#3622. - Include
HEADin theAllowheader ofHTTPEndpoint405 responses whenGETis defined #3585. - Match host names case-insensitively in
Hostrouting andTrustedHostMiddleware#3542. - Preserve every existing
Varyheader inMutableHeaders.add_vary_header(), used byGZipMiddlewareandSessionMiddleware#3675.
Full changelog: 1.8.0...1.9.0
Version 1.8.0
This release adds HTTP 103 Early Hints, preserves response trailers through GZipMiddleware, and stops FileResponse transfers when clients disconnect. Starlette now requires Python 3.11.
Added
- Add
Request.send_early_hints()for HTTP 103 Early Hints through the ASGIhttp.response.early_hintextension #3435.
Changed
- Require Python 3.11 or later, dropping support for Python 3.10 #3592.
- Exclude native gRPC media types (
application/grpcandapplication/grpc+...) fromGZipMiddlewarecompression by default #3565. - Send
http.response.startimmediately inGZipMiddlewarefor responses with an existingContent-Encoding, status206, or an excluded content type, instead of waiting for the first body chunk #3631. - Resolve the multipart charset once per request instead of once per field #3618.
Fixed
- Preserve response trailers through
GZipMiddleware#3565. - Stop
FileResponsetransfers when the client disconnects #3523. - Stop multipart range responses when the file ends before a range is complete, instead of looping forever #3583.
- Ignore
RangewhenIf-Rangecontains a weak ETag #3567. - Include
Allow: GET, HEADinStaticFiles405responses #3640. - Close
Request.stream()generators deterministically, avoiding "Exception ignored" errors with stackedBaseHTTPMiddleware#3628. - Add
Vary: CookiewhenSession.pop()removes an existing key #3186. - Emit
Max-Age=0on the session cookie whenSessionMiddlewareusesmax_age=0#3651. - Bracket IPv6 hostnames in
URL.replace()#3617.
Full changelog: 1.7.0...1.8.0
Version 1.7.0
This release adds experimental OpenTelemetry tracing, HTTP QUERY support, and response trailers in TestClient. Starlette now requires AnyIO 4.
Warning
OpenTelemetryMiddleware is experimental. Its API and emitted telemetry may change in minor releases without a deprecation period.
Added
- Add experimental
OpenTelemetryMiddlewarefor HTTP server spans, with URL exclusions and custom tracer providers #3438, #3463, and #3520. - Expose the matched route through
scope["route"]#3438. - Support the
QUERYHTTP method inHTTPEndpoint, CORS, and OpenAPI 3.2 schema generation #3489. - Capture HTTP response trailers in
TestClientand expose them throughresponse.extensions["http.response.trailers"]#3563. - Support partitioned cookies in
SessionMiddleware#3510. - Add
partitionedtoResponse.delete_cookie()on Python 3.14 and later #3376. - Support IPv6 hosts in
TrustedHostMiddlewareandTestClient#3471. - Support Python 3.15 #3508.
Changed
- Require
anyio>=4.0.0,<5, dropping support for AnyIO 3 #3512. - Raise
WebSocketDisconnected, aRuntimeErrorsubclass, for disconnected WebSocket operations #2767. - Accept
Collection[str]inCORSMiddlewareconfiguration annotations, including sets and frozensets #3518.
Fixed
- Run background tasks only after the response is sent when using
BaseHTTPMiddleware#3476. - Return
400for invalid multipart parser input #3492. - Include
Vary: Originon all normal CORS responses and vary preflight responses by all request headers that affect them #3516 and #3517. - Handle malformed
Hostheaders and IPv6 authorities consistently across URL construction, host routing, and redirect middleware #3472. - Ignore
Rangeheaders whenFileResponsehas a status other than200, preserving its status and full body #3568. - Handle standalone
If-None-Match: *inStaticFiles#3201. - Reject WebSocket requests to
StaticFileswithout raising an assertion error #3532. - Persist session mutations made with
popitem()and|=#3436. - Handle empty and absent payloads in
WebSocketEndpoint.decode()#3372. - Implement
identityonSimpleUserandUnauthenticatedUser#3271. - Allow
HTTPExceptionto use non-standard status codes without an explicitdetail#3545. - Avoid deprecated AnyIO imports in
TestClientand add explicit imports inWSGIMiddlewarefor AnyIO 4.15 compatibility #3498 and #3501. - Offload debug traceback rendering to a worker thread in
ServerErrorMiddleware#2858.
Full changelog: 1.6.0...1.7.0
Version 1.6.0
What's Changed
- Add
max_body_sizetoStarletteand route classes by @Kludex in #3431 - Expose
http.response.debuginfo via response extensions by @y2kbugger in #3130
New Contributors
- @y2kbugger made their first contribution in #3130
Full Changelog: 1.5.1...1.6.0
Version 1.5.1
What's Changed
- Reject inverted single-byte Range like
bytes=5-4by @nikolauspschuetz in #3389 - Limit
FileResponseto 100 ranges by @Kludex in #3430
Full Changelog: 1.5.0...1.5.1
Version 1.5.0
This release is all about giving GZipMiddleware some love. ποΈ
What's Changed
- Add
exclude_content_typesparameter toGZipMiddlewareby @Kludex in #3418 - Flush GZip output for each streamed chunk by @Kludex in #3419
- Skip compression of partial responses in
GZipMiddlewareby @Kludex in #3420 - Expand default excluded content types in
GZipMiddlewareby @Kludex in #3421
Full Changelog: 1.4.1...1.5.0
Version 1.4.1
What's Changed
Full Changelog: 1.4.0...1.4.1
Version 1.4.0
What's Changed
- Lazily allocate GZipMiddleware compression resources by @Kludex in #3407
- Use
zlib.compressobjinstead ofGzipFileinGZipMiddlewareby @Kludex in #3411 - Offload large GZip compression by @Kludex in #3410
New Contributors
- @benberryallwood made their first contribution in #3334
- @lkk7 made their first contribution in #3359
Full Changelog: 1.3.1...1.4.0