starlette-context

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

Downloads
720.8K
Stars
442
Committers
8

Bot releases are hidden (Show)

starlette-context - v0.3.6 Latest Release

Published by tomwojcik over 1 year ago

starlette-context - v0.3.5

Published by tomwojcik almost 2 years ago

starlette-context - v0.3.4

Published by tomwojcik over 2 years ago

  • add 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
  • fix for accessing context during logging, outside of the request-response cycle. Technically it should raise an exception, but it makes sense to include the context by default (in logs) and if it’s not available, some logs are better than no logs. Now it will show context data if context is available, with a fallback to an empty dict (instead of raising an exc) https://github.com/tomwojcik/starlette-context/issues/65
  • add ContextMiddleware deprecation warning
  • **context context unpacking seems to be working now
starlette-context - v0.3.3

Published by tomwojcik over 3 years ago

  • add support for custom error responses if error occurred in plugin / middleware -> fix for 500 (Thanks @hhamana)
  • better (custom) exceptions with a base StarletteContextError (Thanks @hhamana)
starlette-context - v0.3.2

Published by tomwojcik over 3 years ago

  • ContextDoesNotExistError is raised when context object can't be accessed. Previously it was RuntimeError.
    For backwards compatibility, it inherits from RuntimeError so it shouldn't result in any regressions.
  • Added py.typed file so your mypy should never complain
starlette-context - v0.3.1

Published by tomwojcik about 4 years ago

  • add ApiKeyPlugin plugin for X-API-Key header
starlette-context - v0.3.0

Published by tomwojcik about 4 years ago

  • add RawContextMiddleware for Streaming and File responses
  • add flake8, isort, mypy
  • small refactor of the base plugin, moved directories and removed one redundant method (potentially breaking changes)
starlette-context - v0.2.3

Published by tomwojcik about 4 years ago

  • add docs on read the docs
  • fix bug with force_new_uuid=True returning the same uuid constantly
  • due to ^ a lot of tests had to be refactored as well
starlette-context - 0.2.2

Published by tomwojcik over 4 years ago

  • for correlation id and request id plugins, add support for enforcing the generation of a new value
  • for ^ plugins add support for validating uuid. It's a default behavior so will break things for people who don't use uuid4 there. If you don't want this validation, you need to pass validate=False to the plugin
  • thanks to @VukW you can now check if context is available
starlette-context - 0.2.1

Published by tomwojcik over 4 years ago

  • dropped with_plugins from the middleware as Starlette has it's own way of doing this
  • due to ^ this change some tests are simplified
  • if context is not available no LookupError will be raised, instead there will be RuntimeError, because this error might mean one of two things: user either didn't use ContextMiddleware or is trying to access context object outside of request-response cycle
starlette-context - 0.2.0

Published by tomwojcik over 4 years ago

  • changed parent of context object. More or less the API is the same but due to this change the implementation itself is way more simple and now it's possible to use .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()
  • there was an issue related to not having awaitable plugins. Now both middleware and plugins are fully async compatible. It's a breaking change as it forces to use await, hence new minor version
starlette-context - 0.1.6

Published by tomwojcik almost 5 years ago

breaking changes

one middleware, one context, multiple plugins for middleware
very easy testing and writing custom plugins

starlette-context - 0.1.5

Published by tomwojcik almost 5 years ago

lint
tests (100% cov)
separate class for header constants
BasicContextMiddleware add some logic

starlette-context - 0.1.4

Published by tomwojcik almost 5 years ago

  • get_many in context object
  • cicd improvements
  • type annotations
starlette-context - 0.1.3

Published by tomwojcik almost 5 years ago

0.1.2 + fixed setup.py packaging
what has changed:
different API, context object, renamed middlewares

starlette-context - 0.1.2 - never published because of broken setup.py

Published by tomwojcik almost 5 years ago

moved get/set context to context object that wraps contextvar

starlette-context - 0.1.1

Published by tomwojcik almost 5 years ago

added response headers (cid and rid only) for one of the middlewares

starlette-context - mvp

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.

Package Rankings
Top 35.26% on Conda-forge.org
Top 2.67% on Pypi.org
Top 9.55% on Proxy.golang.org
Top 22.94% on Spack.io
Related Projects