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

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_progress-0.1.2.tar.gz
  • Upload date:
  • Size: 3.6 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.2.tar.gz
Algorithm Hash digest
SHA256 cec06006352b8519156ffe57733ec721783f9f5d9cb6f802e06f531c78b9415e
MD5 319133c0065c6242e75aabfb32ad42dc
BLAKE2b-256 01c73411d97310b69ded9cd18645ba41b833285f3517c10ebfcafe05259ebc5c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastapi_progress-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 529d240f631f7979999aabfa97765c1467f38c2fba31a265e7c2742604be6199
MD5 28860bfebe181c2f5db02555a233172a
BLAKE2b-256 d71fcd49f4e11f63d4b568d5f101e43f52a906bb2fde510a240aed6154c1848c

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