Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastapi-pulse

Bridge Celery task lifecycle events to FastAPI Server-Sent Events (SSE) streams.

Features

  • Real-time task progress via SSE — no polling required
  • Pluggable broker backends: Redis, RabbitMQ, or in-process Memory
  • Single route per task: GET /pulse/tasks/{task_id}
  • Bring your own broker by subclassing BaseBroker

Installation

# Core + Redis backend
pip install fastapi-pulse[redis]

# Core + RabbitMQ backend
pip install fastapi-pulse[rabbitmq]

# All backends
pip install fastapi-pulse[all]

Quick start

from fastapi import FastAPI
from celery import Celery
from fastapi_pulse import TaskBridge
from fastapi_pulse.backends import RedisBroker

app = FastAPI()
celery_app = Celery("worker", broker="redis://localhost/0")

bridge = TaskBridge(app, celery_app, broker=RedisBroker(url="redis://localhost"))

Connect from a browser or client:

const es = new EventSource("/pulse/tasks/YOUR_TASK_ID");
es.onmessage = (e) => console.log(JSON.parse(e.data));

Backends

Backend Import Extra
Redis from fastapi_pulse.backends import RedisBroker pip install fastapi-pulse[redis]
RabbitMQ from fastapi_pulse.backends import RabbitMQBroker pip install fastapi-pulse[rabbitmq]
Memory from fastapi_pulse.backends import MemoryBroker built-in

Custom backend

from fastapi_pulse.backends import BaseBroker
from typing import AsyncIterator

class MyBroker(BaseBroker):
    async def publish(self, channel: str, message: str) -> None: ...
    async def subscribe(self, channel: str) -> AsyncIterator[str]: ...
    async def close(self) -> None: ...

Event format

Each SSE data field is a JSON object:

{
  "task_id": "abc-123",
  "event": "success",
  "task": "myapp.tasks.add",
  "timestamp": "2024-01-01T00:00:00+00:00",
  "result": 42
}

event values: started | success | failure | retry | revoked

License

MIT

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages