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.2.tar.gz (4.8 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.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: usageflow_fastapi-0.3.2.tar.gz
  • Upload date:
  • Size: 4.8 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.2.tar.gz
Algorithm Hash digest
SHA256 742c0a1b75a8721c6bb1dee03f91ce99c0807e3b453e7cdf9e4b59d9902f93c8
MD5 be84063758e20ec7242c9ec525dd3df5
BLAKE2b-256 3f1ac586a0155a5d7ba0b7eb56f41d1e0f5ad67924007624eeefdf3d82b13921

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for usageflow_fastapi-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e9baa66e90dc360f0e97f4d204a257b36022964736764da47b5b710b54fa7f9e
MD5 cbd91c2470f9a45de440f6922643fbde
BLAKE2b-256 3cc52a411bd7b51bab3a76c25c32cdb9cee3b3e3fdaf48f6351573258d34e299

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