Skip to main content

FastAPI middleware for UsageFlow - Usage-based pricing made simple

Project description

UsageFlow FastAPI

FastAPI middleware for UsageFlow - Usage-based pricing made simple.

Installation

pip install usageflow-fastapi

Usage

from fastapi import FastAPI
from usageflow.fastapi import UsageFlowMiddleware

app = FastAPI()

# Initialize UsageFlow middleware
app.add_middleware(
    UsageFlowMiddleware,
    api_key="your-api-key",
    pool_size=10,  # Optional: Number of WebSocket connections (default: 10)
    whitelist_routes=["/health", "/metrics"],  # Optional: routes to skip tracking
    tracklist_routes=["/api/v1"]  # Optional: routes to track specifically
)

@app.get("/api/v1/users")
async def get_users():
    return {"users": ["user1", "user2"]}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

Configuration

The middleware accepts the following parameters:

  • app: Your FastAPI application instance (passed via add_middleware)
  • api_key: Your UsageFlow API key (required)
  • pool_size (optional): Number of WebSocket connections in the pool (default: 10)
  • whitelist_routes (optional): List of routes to skip tracking
  • tracklist_routes (optional): List of routes to track specifically

Features

  • Automatic usage tracking
  • Request/response logging
  • Rate limiting and quota management
  • User identification via JWT tokens
  • Custom metadata support
  • Async support
  • Endpoint blocking support
  • Whitelist and tracklist route filtering

Documentation

For full documentation, visit https://docs.usageflow.io

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

usageflow_fastapi-0.3.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

usageflow_fastapi-0.3.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file usageflow_fastapi-0.3.1.tar.gz.

File metadata

  • Download URL: usageflow_fastapi-0.3.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for usageflow_fastapi-0.3.1.tar.gz
Algorithm Hash digest
SHA256 d352ef3d210cdc18659b9b7d9ab3ea97b77475f6cb301d065a0c331dda40fec4
MD5 add2b437bc2541fb9f08facd54a4d5c9
BLAKE2b-256 79c802b964b93d6ad6524a718c31ec9b9a54bbd7f97df37d93da26ce21de1519

See more details on using hashes here.

File details

Details for the file usageflow_fastapi-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for usageflow_fastapi-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 de126a732b36eb8a1aeb5bf24662eab711b3af71372efa09470b58a076dcc2de
MD5 50100c1c4a727759925332c6ba1413b9
BLAKE2b-256 38295e0d483ecf7f02366bcf9fd8d9a3219c8505c54db2cdbadb16daf7048776

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