All Projects → tomwojcik → starlette-context

tomwojcik / starlette-context

Licence: MIT license
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.

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects
Makefile
30231 projects

Projects that are alternatives of or similar to starlette-context

fastapi-websocket-broadcast
Websocket 'broadcast' demo using FastAPI/Starlette
Stars: ✭ 106 (-66.87%)
Mutual labels:  starlette, fastapi
arel
Lightweight browser hot reload for Python ASGI web apps
Stars: ✭ 69 (-78.44%)
Mutual labels:  starlette, fastapi
morelia server
Server for MoreliaTalk network
Stars: ✭ 25 (-92.19%)
Mutual labels:  starlette, fastapi
inboard
🚢 Docker images and utilities to power your Python APIs and help you ship faster. With support for Uvicorn, Gunicorn, Starlette, and FastAPI.
Stars: ✭ 106 (-66.87%)
Mutual labels:  starlette, fastapi
Awesome Fastapi
A curated list of awesome things related to FastAPI
Stars: ✭ 3,033 (+847.81%)
Mutual labels:  starlette, fastapi
starlette-opentracing
Opentracing support for Starlette and FastApi
Stars: ✭ 62 (-80.62%)
Mutual labels:  starlette, fastapi
fastapi-tdd-docker
Test-Driven Development with FastAPI and Docker
Stars: ✭ 89 (-72.19%)
Mutual labels:  starlette, fastapi
starlette-discord
"Login with Discord" support for Starlette and FastAPI
Stars: ✭ 15 (-95.31%)
Mutual labels:  starlette, fastapi
serverless-mangum-examples
Example ASGI applications and Serverless Framework configurations using Mangum
Stars: ✭ 26 (-91.87%)
Mutual labels:  starlette, fastapi
fastapi-users
Ready-to-use and customizable users management for FastAPI
Stars: ✭ 1,920 (+500%)
Mutual labels:  starlette, fastapi
fastapi-zeit-now
A simple example of deploying FastAPI as a Zeit Serverless Function
Stars: ✭ 24 (-92.5%)
Mutual labels:  starlette, fastapi
Fastapi
FastAPI framework, high performance, easy to learn, fast to code, ready for production
Stars: ✭ 39,588 (+12271.25%)
Mutual labels:  starlette, fastapi
msgpack-asgi
Drop-in MessagePack support for ASGI applications and frameworks
Stars: ✭ 100 (-68.75%)
Mutual labels:  starlette, fastapi
starlette-graphene3
An ASGI app for using Graphene v3 with Starlette / FastAPI
Stars: ✭ 52 (-83.75%)
Mutual labels:  starlette, fastapi
FRDP
Boilerplate code for quick docker implementation of REST API with JWT Authentication using FastAPI, PostgreSQL and PgAdmin ⭐
Stars: ✭ 55 (-82.81%)
Mutual labels:  fastapi
webargs-starlette
Declarative request parsing and validation for Starlette with webargs
Stars: ✭ 36 (-88.75%)
Mutual labels:  starlette
pytorch-serving
[UNMAINTAINED] A starter pack for creating a lightweight responsive web app for Fast.AI PyTorch models.
Stars: ✭ 16 (-95%)
Mutual labels:  starlette
fastapi-admin
A fast admin dashboard based on FastAPI and TortoiseORM with tabler ui, inspired by Django admin
Stars: ✭ 1,765 (+451.56%)
Mutual labels:  fastapi
ms-fastapi-template
This project was built as a result of a deepening of the studies discussed on the blog farlley.com with a greater focus on Domain Driven Design (DDD) architecture. In this work you will find a simple template for creating microservices, as well as a use case (which will still be implemented according to the Roadmap found in this same document) a…
Stars: ✭ 31 (-90.31%)
Mutual labels:  fastapi
python-in-browser
🐍🛥🌟 Running Python in the browser with Batavia and Starlette
Stars: ✭ 12 (-96.25%)
Mutual labels:  starlette

Test Suite Python PyPI version codecov Docs Downloads

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.

Resources:

Installation

Python ~3.7.0

$ pip install starlette-context==0.3.5

Python ^3.8

$ pip install starlette-context>=0.3.6

Dependencies

  • starlette

Example

import uvicorn

from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.requests import Request
from starlette.responses import JSONResponse

from starlette_context import context, plugins
from starlette_context.middleware import RawContextMiddleware

middleware = [
    Middleware(
        RawContextMiddleware,
        plugins=(
            plugins.RequestIdPlugin(),
            plugins.CorrelationIdPlugin()
        )
    )
]

app = Starlette(middleware=middleware)


@app.route("/")
async def index(request: Request):
    return JSONResponse(context.data)


uvicorn.run(app, host="0.0.0.0")

In this example the response contains a json with

{
  "X-Correlation-ID":"5ca2f0b43115461bad07ccae5976a990",
  "X-Request-ID":"21f8d52208ec44948d152dc49a713fdd"
}

Context can be updated and accessed at anytime if it’s created in the middleware.

Sponsorship

A huge thank you to Adverity for sponsoring the development of this OSS library in 2022.

Contribution

See the guide on read the docs.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].