Python Quick Start
Installation
Section titled “Installation”pip install sayiirSimple workflow
Section titled “Simple workflow”Define tasks with @task and chain them with Flow:
from sayiir import task, Flow, run_workflow
@taskdef fetch_user(user_id: int) -> dict: return {"id": user_id, "name": "Alice"}
@taskdef send_email(user: dict) -> str: return f"Sent welcome to {user['name']}"
workflow = Flow("welcome").then(fetch_user).then(send_email).build()result = run_workflow(workflow, 42)print(result) # "Sent welcome to Alice"Make it durable
Section titled “Make it durable”Use run_durable_workflow to checkpoint after each task. If the process crashes, call resume_workflow to continue from the last checkpoint.
from sayiir import task, Flow, run_durable_workflow, InMemoryBackend
@task(timeout_secs=30)def process_order(order_id: int) -> dict: return {"order_id": order_id, "status": "processed"}
@taskdef send_confirmation(order: dict) -> str: return f"Confirmed order {order['order_id']}"
workflow = Flow("order").then(process_order).then(send_confirmation).build()
# Checkpoints after each task — resume from last checkpoint on crashstatus = run_durable_workflow(workflow, "order-123", 42)print(status.output)With PostgreSQL
Section titled “With PostgreSQL”Swap to PostgresBackend for production — everything else stays the same:
from sayiir import PostgresBackend
# Connects and runs migrations automaticallybackend = PostgresBackend("postgresql://localhost/sayiir")status = run_durable_workflow(workflow, "order-123", 42, backend=backend)Pydantic integration
Section titled “Pydantic integration”Sayiir automatically validates inputs and outputs when you use Pydantic models:
from pydantic import BaseModelfrom sayiir import task, Flow, run_workflow
class OrderInput(BaseModel): order_id: int amount: float
class OrderResult(BaseModel): status: str message: str
@taskdef process(order: OrderInput) -> OrderResult: return OrderResult(status="ok", message=f"Processed ${order.amount}")
workflow = Flow("typed").then(process).build()result = run_workflow(workflow, {"order_id": 1, "amount": 99.99})Pydantic models are serialized and deserialized automatically at each checkpoint boundary.
Next steps
Section titled “Next steps”- Retries & Timeouts — exponential backoff, timeout behavior
- Signals & Events — wait for external events
- Parallel Workflows — fork/join parallelism
- Durable Workflows — lifecycle operations, delays
- PostgreSQL in Production — connection pooling, operational tips