Skip to main content

z4j FastAPI framework adapter (Apache 2.0)

Project description

z4j-fastapi

PyPI version Python License

License: Apache 2.0

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

Pick your task engine and install with the matching extra. Each extra pulls the engine adapter AND its companion scheduler in one shot, so a fresh install never needs a second command.

pip install z4j-fastapi[arq]        # arq + arq-cron (async-native, recommended)
pip install z4j-fastapi[taskiq]     # TaskIQ + taskiq-scheduler (async, broker-flexible)
pip install z4j-fastapi[celery]     # Celery + celery-beat (sync stack)
pip install z4j-fastapi[rq]         # RQ + rq-scheduler
pip install z4j-fastapi[dramatiq]   # Dramatiq + APScheduler
pip install z4j-fastapi[huey]       # Huey + huey-periodic
pip install z4j-fastapi[all]        # every engine (CI / kitchen sink)

pip install z4j-fastapi (no extra) installs only the framework adapter. That's useful if you already manage engine packages elsewhere; otherwise always pick an engine extra.

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.1.2.tar.gz (24.1 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.1.2-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for z4j_fastapi-1.1.2.tar.gz
Algorithm Hash digest
SHA256 c283f221c86bdcf965556ec80c0eb6bceaf8b952d0ae4713070c4b25c985c63d
MD5 b99bc4c47cb1b1ab4447141e30307c48
BLAKE2b-256 1a9b90c7b084d239f08c5fa3be6034644cfbb3e28893ecd609916fd331efb0a2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for z4j_fastapi-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9996b5fb7f92a0092b8c36c044f3d26ca2cab9c28e1325ad36950c8f74355360
MD5 ccd7e494af7cde0acaa5234f89013c4d
BLAKE2b-256 4b478fba8fe10134149b5577abadf56c1d7471ba6dbe086d3a71f1f4244bc0f8

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