Skip to main content

UsageFlow for Flask

Meter selected Flask routes and inspect their traces in the UsageFlow Console.

Use Python 3.10 or newer. Although the current package metadata advertises Python 3.6+, the source uses Python 3.10 syntax.

1. Install

python -m pip install usageflow-flask

View usageflow-flask on PyPI.

2. Set the API key

Create an application and API key in the Console, then set it in the process environment:

export USAGEFLOW_API_KEY="your-api-key"

The package does not require python-dotenv.

3. Register the middleware

Register one UsageFlowMiddleware instance on the Flask application before the application begins serving requests:

import os

from flask import Flask, jsonify
from usageflow.flask import UsageFlowMiddleware

app = Flask(__name__)


@app.get("/api/hello")
def hello():
    return jsonify({"message": "hello"})


usageflow = UsageFlowMiddleware(
    app,
    api_key=os.environ["USAGEFLOW_API_KEY"],
)

Flask integration uses the constructor directly; do not use app.add_middleware.

4. Select routes in the Console

For the application that owns the API key, add a monitoringPaths entry for the first route:

method: GET
url: /api/hello

Use whitelistEndpoints for routes that must be skipped. A whitelist match wins over a monitoring match. The middleware refreshes Console configuration about every 10 seconds.

Important: an empty monitoring map skips all requests. It does not enable monitor-all behavior. Configure a monitoring path and wait for a refresh before testing.

Methods can be an HTTP method or *. URL * matches every path. A URL that contains * acts as a prefix after the * characters are removed, not as a general glob or regular expression. For example, /api/users/* matches /api/users/123.

Current limitation: when several URL patterns use the same method, only the first pattern may be evaluated. Prefer one prefix or * entry per method.

Flask route selection compares Console paths with the concrete request path. For a dynamic Flask route such as /users/<user_id>, monitor a suitable prefix such as /users/*, or list the concrete paths you intend to meter.

5. Send a request

Start the application, allow up to 10 seconds for the first configuration refresh, then call the monitored route:

curl -i http://127.0.0.1:5000/api/hello

6. Verify the first Trace

Open the application's Traces view in the Console and confirm a GET /api/hello trace appears. If it does not appear, wait for another refresh and send one more request.

Production and security notes

  • UsageFlow records request method, route/path information, client and user-agent data, headers, query/path parameters, and JSON request bodies. It records response status, headers, duration, and a schema derived from JSON responses; it does not attach the full response body to trace metadata.
  • Request header names containing key are redacted. Other headers and JSON body fields are not automatically redacted, so avoid monitoring routes that expose secrets unless your data handling policy allows it.
  • Policy identity may come from a path parameter, query parameter, JSON body field, header, bearer-token claim, cookie, or configured claim in a JWT cookie. JWTs are decoded without signature verification for identity extraction. Your application remains responsible for authentication and authorization.
  • Connectivity and telemetry failures generally fail soft: the Flask request continues without UsageFlow tracking. An explicit policy decision, including endpoint blocking or a denied usage request, can intentionally reject traffic.

Troubleshooting

  • No Trace: confirm the API key belongs to the selected Console application, monitoringPaths is not empty, the method and concrete path match, and the route is not whitelisted. Wait at least 10 seconds after Console changes.
  • Dynamic route does not match: Flask filtering sees the concrete path; use a prefix such as /users/*.
  • Application does not connect: confirm USAGEFLOW_API_KEY is present in the server process and outbound secure WebSocket access is allowed.
  • Request is denied: check the application's UsageFlow endpoint and usage policies. Fail-soft connectivity behavior does not override an explicit policy denial.

Metadata

Release files for usageflow-flask 0.3.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for usageflow-flask 0.3.6
File Size Uploaded Provenance Actions
usageflow_flask-0.3.6.tar.gz 11.2 kB Without provenance Details for usageflow_flask-0.3.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for usageflow-flask 0.3.6
File Interpreter ABI Platform Actions
usageflow_flask-0.3.6-py3-none-any.whl Python 3 none any Details for usageflow_flask-0.3.6-py3-none-any.whl

Total release size: 18.6 kB

Release files / usageflow_flask-0.3.6.tar.gz

Download URL usageflow_flask-0.3.6.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
533367df577cca5920412f4a6a6fc5af7ec95645314ec166a4ea5dbb9c6e930f
BLAKE2b-256 checksum
How to use checksums
5ecd809e815a70ef4c559e23cd09c63ebf0d6cbde96cb7713931a53e0f899eb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.0

Release files / usageflow_flask-0.3.6-py3-none-any.whl

Download URL usageflow_flask-0.3.6-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bdc3ce06f0395eb0588a6b0d7494953c2fb940edf967349233164b098b3e6a36
BLAKE2b-256 checksum
How to use checksums
003fb268decf66f0d3a78e523639486b93e99dc403f94a6c944bc3104dd892b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.0

Security for usageflow-flask 0.3.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page