Skip to main content

z4j FastAPI framework adapter (Apache 2.0)

Project description

z4j-fastapi

PyPI version Python License

License: Apache 2.0 Status: v1.0.0 — first public release.

FastAPI framework adapter for z4j. Integrates via FastAPI's lifespan hook — one context manager wraps the agent's lifecycle with your app's startup and shutdown.

Install

# FastAPI + arq (the most common async-native pairing)
pip install z4j-fastapi z4j-arq z4j-arqcron

# FastAPI + Celery (when the sync stack is preferred)
pip install z4j-fastapi z4j-celery z4j-celerybeat

# FastAPI + Dramatiq / RQ / Huey / taskiq — all supported
pip install z4j-fastapi z4j-dramatiq z4j-apscheduler
pip install z4j-fastapi z4j-taskiq z4j-taskiqscheduler

Configure

Mount the z4j lifespan in your FastAPI app:

from contextlib import asynccontextmanager
from fastapi import FastAPI
from z4j_fastapi import Z4JLifespan

z4j = Z4JLifespan(
    brain_url="https://z4j.internal",
    token="z4j_agent_...",        # minted in the brain dashboard
    project_id="my-project",
)

@asynccontextmanager
async def lifespan(app: FastAPI):
    async with z4j(app):
        yield

app = FastAPI(lifespan=lifespan)

Or, if you have no other lifespan logic:

from z4j_fastapi import Z4JLifespan

app = FastAPI(lifespan=Z4JLifespan(
    brain_url="https://z4j.internal",
    token="z4j_agent_...",
    project_id="my-project",
))

On uvicorn startup the agent connects to the brain and z4j's dashboard populates with every arq / Celery / Dramatiq / taskiq / Huey task your workers register.

What it does

Piece Purpose
Z4JLifespan(...) Async context manager matching FastAPI's lifespan contract
Graceful shutdown Flushes the event buffer on await lifespan.aclose()
Async-native Uses asyncio.create_task — never blocks the event loop

Reliability

z4j-fastapi follows the project-wide safety rule: z4j never breaks your FastAPI app. Agent failures are caught at the boundary and never propagate into your request handlers.

Documentation

License

Apache 2.0 — see LICENSE. Your FastAPI application is never AGPL-tainted by importing z4j_fastapi.

Links

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

z4j_fastapi-1.0.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

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

z4j_fastapi-1.0.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file z4j_fastapi-1.0.0.tar.gz.

File metadata

  • Download URL: z4j_fastapi-1.0.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for z4j_fastapi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 42a5da0cad0efaa5d1661f7d1608c652e7ac8af23bf98ba3742d79b02dce451f
MD5 97d014635dc7039e3d1b43968be941c9
BLAKE2b-256 430b78130514b79fd44074fce02114f6f22435ff0304cddae566c2c843ac9d6b

See more details on using hashes here.

File details

Details for the file z4j_fastapi-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: z4j_fastapi-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for z4j_fastapi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 791afe0efbb75f292a1d0dabd20475a5ed53cbef94b2c32b967e4a8807896143
MD5 ed4e269f12fcf50e9c9b7d71107cb500
BLAKE2b-256 42165f960c40d6089d3807dea4c5ec99b1a22733553b919359a34f89acdf4526

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