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)
)

@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)

Note: Whitelist and tracklist routes are now managed server-side via the UsageFlow dashboard, not through local parameters.

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
  • Server-side 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.3.tar.gz (5.7 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.3-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: usageflow_fastapi-0.3.3.tar.gz
  • Upload date:
  • Size: 5.7 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.3.tar.gz
Algorithm Hash digest
SHA256 c045bdfdb9710cd09d4417a8d5cf4cb9fa50fc53d9ba1e63da08604c6cbe4c91
MD5 d8d19ad294a83f92bbd3e09f3027591d
BLAKE2b-256 785dde9db69025c91fe0e6b79bd450a276f372f1e88216d7450451eb3fe7bc51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for usageflow_fastapi-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 84a72dce6efb0e4ac01d9e52af73b8241a33a8eb13a28663439310dd69ab95f2
MD5 8d840499b8258f70f06442ce6a572dec
BLAKE2b-256 c674e88a469006ca06cc89528f8506c61bfc5a08d3374fe4c3732ca08ba3bd40

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