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 viaadd_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.
Release files for usageflow-fastapi 0.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| usageflow_fastapi-0.3.4.tar.gz | 9.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| usageflow_fastapi-0.3.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.0 kB
Release files / usageflow_fastapi-0.3.4.tar.gz
| Download URL | usageflow_fastapi-0.3.4.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
386fbaeda43c4487fb3f83bb0abfcf27fa2a43249044ca26a2c8b86db0dd4364
|
|
BLAKE2b-256 checksum How to use checksums |
191177c905983e8e25db305ce4e2ed611b218db55a7ca735116960795b59b7b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / usageflow_fastapi-0.3.4-py3-none-any.whl
| Download URL | usageflow_fastapi-0.3.4-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d61c5a57e9747d2ee236cadba27d58893f32a9679cce707a69e9822c75a40ebb
|
|
BLAKE2b-256 checksum How to use checksums |
2726ac4fcf5000dbd64f43db0a852e26b64ca86f42e72c239c1b0bfd69469981
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|