NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #2975 most downloaded on PyPI
Middleware for Starlette that allows you to store and access the context data of a request. Can be used with logging so logs automatically use request headers such as x-request-id or x-correlation-id.
Last release 7 months ago
28 Feb 2026
Release timing varies
gaps range from 2 months to 2.0 years
Nearly every release is documented
notes for 20 of 20 stable releases
Nothing withdrawn
no release was ever pulled
7 years old
20 releases · first in 2019
Fix HeaderKeys enum str() behavior inconsistency across Python versions ( #192 ). On Python 3.11+, str(HeaderKeys.api_key) returned "HeaderKeys.api_ke
HeaderKeys enum str() behavior inconsistency across Python versions (#192). On Python 3.11+, str(HeaderKeys.api_key) returned "HeaderKeys.api_key" instead of "X-API-Key". Now uses StrEnum for consistent behavior across all supported Python versions.Replace deprecated HTTP_422_UNPROCESSABLE_ENTITY with HTTP_422_UNPROCESSABLE_CONTENT
assert with ConfigurationError in Plugin.process_request for clearer error messagesruff format for code formattingHTTP_422_UNPROCESSABLE_ENTITY with HTTP_422_UNPROCESSABLE_CONTENTOne column per quarter.
Drop ContextMiddleware deprecation warning as Starlette no longer plans to deprecate it ( Kludex/starlette#2160 (comment) )
ContextMiddleware deprecation warning as Starlette no longer plans to deprecate it ( Kludex/starlette#2160 (comment) )starlette-context potentially breaking if ContextMiddleware is used along with starlette>=0.41.3 ( #151 )fix for being unable to catch some exceptions with a try/except due to base exc inheriting from the BaseException (Thanks @soundstripe ) #90
BaseException (Thanks @soundstripe) #90fix for accessing the context in error handlers (Thanks @hhamana ) #74
add ContextMiddleware deprecation warning
request_cycle_context. It’s a context manager that allows for easier testing and cleaner code (Thanks @hhamana) #46ContextMiddleware deprecation warning**context context unpacking seems to be working nowadd support for custom error responses if error occurred in plugin / middleware -> fix for 500 (Thanks @hhamana )
ContextDoesNotExistError is raised when context object can't be accessed. Previously it was RuntimeError . For backwards compatibility, it inherits fr
ContextDoesNotExistError is raised when context object can't be accessed. Previously it was RuntimeError.RuntimeError so it shouldn't result in any regressions.py.typed file so your mypy should never complainadd ApiKeyPlugin plugin for X-API-Key header
small refactor of the base plugin, moved directories and removed one redundant method (potentially breaking changes)
RawContextMiddleware for Streaming and File responsesfix bug with force_new_uuid=True returning the same uuid constantly
force_new_uuid=True returning the same uuid constantlyfor correlation id and request id plugins, add support for enforcing the generation of a new value
validate=False to the plugindropped with_plugins from the middleware as Starlette has it's own way of doing this
with_plugins from the middleware as Starlette has it's own way of doing thiscontext object outside of request-response cycleNow both middleware and plugins are fully async compatible. It's a breaking change as it forces to use await, hence new minor version
.items() or keys() like in a normal dict, out of the box. Still, unpacking **kwargs is not supported and I don't think it ever will be. I tried to inherit from the builtin dict but nothing good came out of this. Now you access context as dict using context.data, not context.dict()one middleware, one context, multiple plugins for middleware very easy testing and writing custom plugins
breaking changes
one middleware, one context, multiple plugins for middleware very easy testing and writing custom plugins
lint tests (100% cov) separate class for header constants BasicContextMiddleware add some logic
lint tests (100% cov) separate class for header constants BasicContextMiddleware add some logic
- get_many in context object - cicd improvements - type annotations
get_many in context object
cicd improvements
type annotations
MVP until 0.1.4
experiments and tests with ContextVar
MVP until 0.1.4
0.1.2 + fixed setup.py packaging what has changed: different API, context object, renamed middlewares
0.1.2 + fixed setup.py packaging what has changed: different API, context object, renamed middlewares
added response headers (cid and rid only) for one of the middlewares
added response headers (cid and rid only) for one of the middlewares
Working starlette_context, but not production ready. Needs to be tested. No idea if contextvar can be trusted.
Working starlette_context, but not production ready. Needs to be tested. No idea if contextvar can be trusted.
Your coding agent can read these notes before it upgrades. Set up the MCP server →