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.4.tar.gz (9.2 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.4-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: usageflow_fastapi-0.3.4.tar.gz
  • Upload date:
  • Size: 9.2 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.4.tar.gz
Algorithm Hash digest
SHA256 386fbaeda43c4487fb3f83bb0abfcf27fa2a43249044ca26a2c8b86db0dd4364
MD5 e7d2131fed48484c20b93bddcfbed684
BLAKE2b-256 191177c905983e8e25db305ce4e2ed611b218db55a7ca735116960795b59b7b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for usageflow_fastapi-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d61c5a57e9747d2ee236cadba27d58893f32a9679cce707a69e9822c75a40ebb
MD5 a9a4b9e1ebb7343d264fc59d9e49dcc3
BLAKE2b-256 2726ac4fcf5000dbd64f43db0a852e26b64ca86f42e72c239c1b0bfd69469981

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