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.0.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.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_progress-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 da1d8ca3dcceb7f3200d4a4630cfde96c5e3dc30aa1ba775e52b2998cd39c7b5
MD5 473c3a09b554058c881d25dfbc8b860e
BLAKE2b-256 e42a0d835f0ea96f37e04aeee60badb202eb7aec9bdad6b476ec098880ed2a13

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastapi_progress-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8810eebb8a6c24d6fd29dd05b4481535a829fee87a4cef0e9fadb4905ffb9d0c
MD5 fa8b500e6a84ff0ff3c507bf69ee7fec
BLAKE2b-256 38a7a226ce8ba92b92d3d8586fddf24fcd8c507e2eb1deeb77f9101129a4e0b5

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