Skip to main content

Zero-config background task progress tracker for FastAPI using WebSockets.

Project description

fastapi-progress

A zero-config library to track the progress of FastAPI background tasks and stream it to the frontend via WebSockets in real-time.

Features

  • Zero-config WebSockets: Automatically injects a /ws/progress/{task_id} endpoint.
  • Elegant Decorator: Use @track_progress on your background tasks.
  • Context-aware Updates: Simply call await progress.update(50, "Processing") from anywhere in your task without passing task IDs around.
  • Hybrid State Backend: Includes an in-memory backend for simple deployments, and a Redis backend for distributed setups (e.g., Celery, multiple Uvicorn workers).

Installation

Using uv (recommended):

uv add fastapi-progress

Or pip:

pip install fastapi-progress

Quick Start

import asyncio
import uuid
from fastapi import FastAPI, BackgroundTasks
from fastapi_progress import init_progress, track_progress, progress

app = FastAPI()

# 1. Initialize to inject the websocket route
init_progress(app)

# 2. Decorate your background task
@track_progress(task_id_param="task_id")
async def heavy_work(task_id: str):
    await progress.update(10, "Starting work...")
    await asyncio.sleep(1)
    
    await progress.update(50, "Processing data...")
    await asyncio.sleep(2)
    
    await progress.update(100, "Done!")

# 3. Trigger the task
@app.post("/do-work")
async def start_work(tasks: BackgroundTasks):
    task_id = str(uuid.uuid4())
    tasks.add_task(heavy_work, task_id=task_id)
    return {"task_id": task_id}

Using Redis (For Production)

If you are running multiple Gunicorn/Uvicorn workers, you must use Redis to share the state across processes.

from redis.asyncio import Redis
from fastapi_progress import init_progress, RedisBackend

redis_client = Redis(host="localhost", port=6379)
backend = RedisBackend(redis_client)

init_progress(app, backend=backend)

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

fastapi_progress-0.1.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_progress-0.1.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_progress-0.1.1.tar.gz.

File metadata

  • Download URL: fastapi_progress-0.1.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for fastapi_progress-0.1.1.tar.gz
Algorithm Hash digest
SHA256 70e9abe8f3fc0dac978e3687fc55d3f766bbcf768e2b9ee03dccc6896edff22d
MD5 9d2e30e41f0615960478c04dfb4f0eac
BLAKE2b-256 066634b9bfe052493ade9d98f5a31edf29860ee6bb969d0b4539879931015013

See more details on using hashes here.

File details

Details for the file fastapi_progress-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fastapi_progress-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for fastapi_progress-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1af30eff9acad0f9385a1d0436dfff47d0a244f6e3b25fbd897c66fdcf4dc803
MD5 a6fe8c145b841b068a489b94f080b78f
BLAKE2b-256 93688ee22e31c914f114531bac455686bdfab82601af2bbd12e19e243e5397e0

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