fastapi with support of long running operations
Project description
FastAPI-LRO
FastAPI-LRO is a drop-in replacement for FastAPI that automatically turns all endpoints into long-running asynchronous tasks.
Instead of blocking request/response cycles, every endpoint execution is converted into a background job handled by workers, with built-in job management APIs.
Key Ideas
- Every endpoint runs as an async job by default
- Requests return a job ID immediately
- Results are fetched via provided job endpoints
- Optional endpoint to block until job completion
- Scales horizontally by spawning multiple workers
- Uses Redis as the job backend
Features
- Drop-in FastAPI replacement
- Automatic LRO behavior for all endpoints
- Default job management endpoints
- Blocking and non-blocking result retrieval
- Multiple worker support
- Redis-backed job storage
- Minimal configuration
Default Behavior
All endpoints are treated as long-running operations automatically.
To disable LRO for a specific endpoint, pass the not_lro parameter to the decorator:
@app.get("/health", not_lro=True)
def health():
return {"status": "ok"}
Job Endpoints
FastAPI-LRO provides default endpoints to manage jobs:
- Get job result
- Get job status
- Block until job completion
These endpoints allow clients to poll or wait synchronously for results without blocking workers.
Running the API
Start the API normally (same as FastAPI):
uvicorn fastapi_lro.main:app --reload
Running Workers
Workers execute the background jobs.
python -m fastapi_lro <app_location>:<app_name> --worker
Example:
python -m fastapi_lro <app_location>:<app_name> --worker
You can spawn multiple workers to scale processing:
python -m fastapi_lro app.main:app --worker
python -m fastapi_lro app.main:app --worker
Redis Configuration
FastAPI-LRO requires Redis. Configure Redis via environment variables:
export REDIS_HOST=0.0.0.0
export REDIS_PORT=6379
Defaults:
- redis_host = 0.0.0.0
- redis_port = 6379
Typical Flow
- Client calls an API endpoint
- Server immediately returns a job ID
- Worker processes the task asynchronously
- Client fetches the result or blocks until completion
Use Cases
- Long computations
- IO-heavy operations
- External API calls
- Background processing
- Task queues without extra frameworks
Local development
The project includes a Makefile to simplify common development tasks.
Available Commands
Run tests
Runs the full pytest test suite including async tests and coverage:
make test
Format code
Automatically formats the codebase using the configured formatter:
make format
Build the package
Build the package for distribution:
make build
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_lro-0.0.1.tar.gz.
File metadata
- Download URL: fastapi_lro-0.0.1.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
360c68c155476a5bcd83150e928f08a04e39a867a03bbdfb62cdb6a4f586f0bd
|
|
| MD5 |
dab7664d381e584742e433bc6122ba55
|
|
| BLAKE2b-256 |
5d65aaf69ba853a95d911ad73b35fb1165a44a7873f7075233798fe2a88cc1fb
|
File details
Details for the file fastapi_lro-0.0.1-py3-none-any.whl.
File metadata
- Download URL: fastapi_lro-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff1500546e823d49569206e3b82311b85b731c6241c8fed5d670d34ebc6bbaaf
|
|
| MD5 |
3c6987829a3d7a0b9795d7a788ff65d1
|
|
| BLAKE2b-256 |
a176d37fa9f4278bf6785304d076607bb82796a1b5245123f1de103aad753581
|