Skip to main content
FastAPI logo

FastAPI

v1.6.8 Apache-2.0

z4j-fastapi ยท Upstream project

Lifespan-hook integration for async stacks.

FastAPI lifespan-aware. Most commonly paired with arq or taskiq (both async-native) but works with Celery or RQ when your sync stack calls for them. Dependency-injection friendly.

Latest
v1.6.8
Released
2026-06-08
License
Apache-2.0

Install

bash
pip install z4j-fastapi
Pick an engine

FastAPI + any task engine

Every extra pulls the engine adapter AND its companion scheduler in one shot, so a fresh install never needs a second command.

Engine Install command Bundled scheduler
Celery pip install z4j-fastapi[celery] celery-beat
RQ pip install z4j-fastapi[rq] rq-scheduler
Dramatiq pip install z4j-fastapi[dramatiq] APScheduler
Huey pip install z4j-fastapi[huey] huey-periodic
arq recommended pip install z4j-fastapi[arq] arq-cron
TaskIQ pip install z4j-fastapi[taskiq] taskiq-scheduler
Every engine (CI / kitchen sink) pip install z4j-fastapi[all] all of the above

pip install z4j-fastapi with no extra installs only the framework adapter. Pick an engine extra for the normal case.

Wire it in

python
from fastapi import FastAPI
from z4j_fastapi import install

app = FastAPI(lifespan=install)
Verify

Confirm the agent reaches the brain

Run the doctor as the same user the service runs under. It probes brain DNS / TCP / TLS / WebSocket upgrade, the on-disk buffer path, and reports auto-detected engines - exits 0 on all-green, 1 on any failure.

bash
python -m z4j_fastapi doctor

Catches the gunicorn-under-www-data silent startup failure (the agent now auto-relocates the buffer to $TMPDIR/z4j-{uid} when $HOME is unwritable), NAT / firewall / cert mismatches, and wrong-token / wrong-project_id problems with a specific failure reason. Add --no-websocket to skip the WS round-trip, --json for scripts. Reference.

What you get

FastAPI-specific features

FastAPI lifespan integration
Async-native (arq / taskiq best fit)
Dependency-injection helpers
Works alongside Celery / RQ too
WebSocket-aware health checks
Engine pairings

FastAPI works with every z4j engine

The framework adapter handles lifecycle and config. Any engine adapter slots in alongside.

Other frameworks

See also

Get started with z4j + FastAPI