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.
MIT License
Bot releases are visible (Hide)
BaseException
(Thanks @soundstripe) https://github.com/tomwojcik/starlette-context/issues/90
Published by tomwojcik almost 2 years ago
Published by tomwojcik over 2 years ago
request_cycle_context
. It’s a context manager that allows for easier testing and cleaner code (Thanks @hhamana) https://github.com/tomwojcik/starlette-context/issues/46
ContextMiddleware
deprecation warning**context
context unpacking seems to be working nowPublished by tomwojcik over 3 years ago
StarletteContextError
(Thanks @hhamana)Published by tomwojcik over 3 years ago
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 complainPublished by tomwojcik about 4 years ago
Published by tomwojcik about 4 years ago
RawContextMiddleware
for Streaming
and File
responsesPublished by tomwojcik about 4 years ago
force_new_uuid=True
returning the same uuid constantlyPublished by tomwojcik over 4 years ago
validate=False
to the pluginPublished by tomwojcik over 4 years ago
with_plugins
from the middleware as Starlette has it's own way of doing thiscontext
object outside of request-response cyclePublished by tomwojcik over 4 years ago
.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()
Published by tomwojcik almost 5 years ago
breaking changes
one middleware, one context, multiple plugins for middleware
very easy testing and writing custom plugins
Published by tomwojcik almost 5 years ago
lint
tests (100% cov)
separate class for header constants
BasicContextMiddleware add some logic
Published by tomwojcik almost 5 years ago
Published by tomwojcik almost 5 years ago
0.1.2 + fixed setup.py packaging
what has changed:
different API, context object, renamed middlewares
Published by tomwojcik almost 5 years ago
moved get/set context to context object that wraps contextvar
Published by tomwojcik almost 5 years ago
added response headers (cid and rid only) for one of the middlewares
Published by tomwojcik almost 5 years ago
Working starlette_context, but not production ready. Needs to be tested. No idea if contextvar
can be trusted.