$npx skillfedfor your agent

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.

Worth itPyPI InternetReleased Feb 20262.4M downloads / moMITPure Python

Decision gist · record as of 2026-08-14

pure-Python wheel — starlette_context-0.5.1-py3-none-any.whl
v0.5.1 · released 2026-02-28 · Python >=3.10 · 1 runtime deps: starlette

Yes. The package is actively maintained, has no known vulnerabilities, low install friction, and solves a real problem in web applications—making request-scoped data available throughout the request lifecycle without manual parameter threading. It is well-suited for any Starlette or FastAPI application that needs structured logging, distributed tracing, or request-scoped state management.AI-flagged interpretation of the facts on this page — verify before relying

Before you install

  • Requires Python 3.10 or later and starlette>=0.27.0.
  • Low friction: pure Python wheel with a single runtime dependency on starlette>=0.27.0.
  • Actively maintained with a recent release and no known vulnerabilities.

License · maintenance · safety

MIT (permissive) — MIT license permits commercial and private use with minimal restrictions; you may use, modify, and distribute this package freely provided you include the license notice.

last release 2026-02-28 (167 days) · last repo commit 2026-06-24 · 611 stars

0 known vulnerabilities (OSV.dev, 2026-08-14) · 2,367,211 downloads/mo, #3,102 on PyPI

Verify before relying

pip install starlette-context

from starlette_context import context, plugins
from starlette_context.middleware import ContextMiddleware
from starlette.applications import Starlette
from starlette.middleware import Middleware

middleware = [
    Middleware(
        ContextMiddleware,
        plugins=(plugins.RequestIdPlugin(), plugins.CorrelationIdPlugin())
    )
]
app = Starlette(middleware=middleware)
context["key"] = "value"  # Access in request handlers
  • Whether the package supports async context isolation across concurrent requests without thread-local or context-var conflicts.
  • Performance overhead of middleware on high-throughput applications.
  • Compatibility with other context-aware middleware or frameworks that also manage request state.
Same gist for agents: .md · .json

What it is and what it does

starlette-context is middleware for the Starlette web framework that manages request-scoped context—data that belongs to a single HTTP request and should be accessible throughout its lifecycle. It wraps Starlette's request handling to provide a thread-safe or async-safe context store, populated by configurable plugins that extract headers (like x-request-id or x-correlation-id) and make them available to your route handlers, logging, and other request-processing code without passing them explicitly through function parameters.

The package ships with built-in plugins for common patterns like request ID and correlation ID extraction, and you can write custom plugins to populate context with application-specific data. This is particularly useful for distributed tracing, structured logging, and audit trails where you want request identifiers to flow automatically through logs and downstream services. It integrates cleanly with Starlette's middleware stack and works with FastAPI applications built on Starlette.

Use it for

  • Automatic request ID injection into logs so all log entries for a request share a common identifier without manual threading.
  • Distributed tracing: propagate correlation IDs through microservices by extracting them from incoming headers and making them available to outbound calls.
  • Audit logging: store user ID or tenant ID in context during request processing and access it in database operations or business logic without parameter passing.
  • Multi-tenant applications: extract and store tenant context from request headers to enforce isolation in downstream database queries or API calls.
  • Request metadata enrichment: populate context with parsed authentication tokens, feature flags, or client metadata for use across handlers.

Worth the install?

AI-flagged interpretation of the facts on this page. Verify before relying on it.

Worth it

Yes.

The package is actively maintained, has no known vulnerabilities, low install friction, and solves a real problem in web applications—making request-scoped data available throughout the request lifecycle without manual parameter threading. It is well-suited for any Starlette or FastAPI application that needs structured logging, distributed tracing, or request-scoped state management.

Install

starlette-context on PyPI

Before you install

Low friction: pure Python wheel with a single runtime dependency on starlette>=0.27.0. Actively maintained with a recent release and no known vulnerabilities.

Requires Python 3.10 or later and starlette>=0.27.0.

License in practice

MIT license permits commercial and private use with minimal restrictions; you may use, modify, and distribute this package freely provided you include the license notice.

Quickstart

pip install starlette-context

from starlette_context import context, plugins
from starlette_context.middleware import ContextMiddleware
from starlette.applications import Starlette
from starlette.middleware import Middleware

middleware = [
    Middleware(
        ContextMiddleware,
        plugins=(plugins.RequestIdPlugin(), plugins.CorrelationIdPlugin())
    )
]
app = Starlette(middleware=middleware)
context["key"] = "value"  # Access in request handlers

Verify before relying

  • Whether the package supports async context isolation across concurrent requests without thread-local or context-var conflicts.
  • Performance overhead of middleware on high-throughput applications.
  • Compatibility with other context-aware middleware or frameworks that also manage request state.

Package facts

LicenseMIT permissive
Python supportSupports the current Python release >=3.10
Install frictionLow. Pure-Python wheel
Runtime dependencies
1 package
starlette
MaintenanceActively maintained 167 days since the last release
Last repo commit
First released
Downloads2,367,211 / month, #3,102 on PyPI 30-day window, as of 2026-08-14
Known vulnerabilitiesNone known OSV.dev, checked 2026-08-14
Classifiers
Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: System AdministratorsLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Internet

Evidence: starlette_context-0.5.1-py3-none-any.whl

Tags

Capabilities
starlette request context middlewarerequest id correlation id loggingstarlette context storagerequest header injection middlewarefastapi request contextstarlette middleware pluginsrequest tracing headers
Topics
request-contextdistributed-tracinglogging-integration
PyPI keywords
fastapimiddlewarestarlette

Let your AI agent find packages like this

Example. Real query, live index.

You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.

wish › “starlette request context middleware”

Give your agent the search over MCP, or paste the wish link into any chat.

More Internet packages

botocore Worth it
PyPI · Internet · released Aug 2026

Botocore provides low-level, data-driven access to Amazon Web Services APIs, serving as the foundation for the AWS CLI and boto3 libraries.

Install it if you need programmatic access to AWS services.

permissive licensepure Python · 3.10+
1.5Bdownloads / mo
aiobotocore Worth it
PyPI · Internet · released Aug 2026

Provides an async client for AWS services using botocore and aiohttp, allowing you to call AWS APIs asynchronously within asyncio-based applications.

Install it if you need to call AWS services from async Python code; it is the standard way to do so.

Apache-2.0pure Python · 3.10+
1.2Bdownloads / mo
pydantic Worth it
PyPI · Python Modules · released May 2026

Pydantic validates Python data structures against type hints, coercing and checking input at runtime to ensure it matches a declared schema.

MITpure Python · 3.9+
1.1Bdownloads / mo
filelock Worth it
PyPI · Libraries · released Aug 2026

Provides a platform-independent file locking mechanism to coordinate access to files across processes and threads.

MITpure Python · 3.10+
717.1Mdownloads / mo
fastapi Worth it
PyPI · Software Development · released Jul 2026

FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.

MITpure Python · 3.10+
568.6Mdownloads / mo
googleapis-common-protos Worth it
PyPI · Internet · released Aug 2026

Provides common Protocol Buffer message definitions used across Google Cloud APIs, enabling Python clients to interact with Google services.

Apache-2.0pure Python · 3.10+
513.7Mdownloads / mo

See also asgi-correlation-id · starlette-csrf · Secweb · starlette-compress · starsessions · starlette · starlette-cramjam · fastapi-events · flask-request-id-header · opentelemetry-instrumentation-asgi