Skip to main content

Receive and return the value of HTTP X-Request-ID header.

Project description

request-id-flask

Attach a unique identifier to every HTTP request in your WSGI or ASGI application.

request-id-flask is implemented as a WSGI and ASGI middleware.

The package will do one of two things:

  1. Read the X-Request-ID HTTP header from a client HTTP request and return the same X-Request-ID HTTP header in the server HTTP response and is stored in the WSGI environ.

  2. Or, when no X-Request-ID HTTP header is present in the client HTTP request, generate a new and unique request_id identifier (using uuid 4) which is stored in the WSGI environ and set as the X-Request-ID HTTP header in the server HTTP responser.

Requirements

  • Python 3.6 or above

Installation

You can install the request-id-flask package using pip:

pip install request-id-flask

However, recommended to add it to the requirements.txt file instead, and install using: pip install -r requirements.txt

request-id-flask

Access the request_id

The REQUEST_ID is stored in the request environ dictionary and may be accessed from anywhere this is available in Flask.

Changelog

Flask Usage

from flask import (
    Flask,
    request
)
from request_id import RequestId

app = Flask(__name__)
RequestId(app)


@app.route('/')
def index():
    request_id = request.environ.get('REQUEST_ID', '')
    return str(request_id)

Quart Usage

from quart import (
    Quart,
    request
)
from request_id import RequestId

app = Quart(__name__)
RequestId(app)


@app.route('/')
async def index():
    request_id = request.environ.get('REQUEST_ID', '')
    return await str(request_id)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

request-id-flask-0.0.4.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

request_id_flask-0.0.4-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file request-id-flask-0.0.4.tar.gz.

File metadata

  • Download URL: request-id-flask-0.0.4.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for request-id-flask-0.0.4.tar.gz
Algorithm Hash digest
SHA256 302fadf7dafdede17994f9f0e5cb7e0f0391306194a7d646bc09e6885d634729
MD5 25411522f21e41a68aed7d428f7e6373
BLAKE2b-256 6cbc78c87c5f16b9c23affc7c5de8097bc6e7e7d53d05ff21fef5e3e35fc79f7

See more details on using hashes here.

File details

Details for the file request_id_flask-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for request_id_flask-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 49a6dc1e3fd93f3d0ce61f1983640d4635bb038818f2341366087c8094424885
MD5 794deafc09b66639ea44dbef726e6045
BLAKE2b-256 75f44c51c2f7fc9d3cb56ce6a353523b9d0722ec64f90b022c210a9487019091

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page