Middleware for Starlette that stores and accesses request context data, enabling automatic logging with headers like x-request-id.
Starlette-context is a middleware for the Starlette ASGI framework that provides a request-scoped context for storing and accessing data throughout an HTTP request's lifecycle. It solves the problem of passing request metadata, like correlation IDs, across different parts of an application without manual propagation, which is essential for logging and debugging in distributed systems.
Developers building ASGI-based web applications with Starlette who need request-scoped data storage, especially for logging, tracing, or passing metadata between middleware and endpoints.
Developers choose starlette-context for its simplicity, built-in plugins for common use cases like request IDs, and seamless integration with Starlette's middleware system, eliminating boilerplate code for context management.
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.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides a request-scoped dictionary that is thread-safe, allowing safe storage and access of arbitrary data throughout the HTTP request lifecycle, as shown in the example with `context["custom_value"]`.
Includes plugins like RequestIdPlugin and CorrelationIdPlugin that automatically capture headers such as x-request-id and x-correlation-id, reducing boilerplate code for common tracing needs.
Integrates easily as Starlette middleware with minimal configuration, demonstrated in the README example using Middleware and ContextMiddleware.
Enables automatic logging with request context, simplifying debugging and traceability in microservices and distributed systems, which is highlighted in the key features.
Tightly coupled to Starlette, making it unusable for projects with other frameworks like FastAPI without workarounds, limiting its versatility.
Only a few built-in plugins are provided; for advanced use cases, developers must create custom plugins, which adds development overhead.
Adding middleware introduces latency, which could be a drawback for high-performance applications where minimal overhead is critical, though not explicitly addressed in the README.