Python SDK for Absurd - PostgreSQL-based durable task execution
Maintained. Last release 6 weeks ago, commits in 6 of the last 26 weeks. Weaker on contributor spread.
pip install absurd-sdkAbsurd SDK for Python
Python SDK for Absurd: a PostgreSQL-based durable task execution system.
Absurd is the simplest durable execution workflow system you can think of. It's entirely based on Postgres and nothing else. It's almost as easy to use as a queue, but it handles scheduling and retries, and it does all of that without needing any other services to run in addition to Postgres.
What is Durable Execution?
Durable execution (or durable workflows) is a way to run long-lived, reliable functions that can survive crashes, restarts, and network failures without losing state or duplicating work. Instead of running your logic in memory, a durable execution system decomposes a task into smaller pieces (step functions) and records every step and decision.
Installation
uv add absurd-sdk
Synchronous API
If you omit the connection argument, the client uses ABSURD_DATABASE_URL,
then PGDATABASE, then postgresql://localhost/absurd.
from absurd_sdk import Absurd
app = Absurd("postgresql://localhost/absurd")
@app.register_task(name="order-fulfillment")
def process_order(params, ctx):
step = ctx.run_step
@step("process-payment")
def payment():
return {
"payment_id": f"pay-{params['order_id']}",
"amount": params["amount"],
}
@step("reserve-inventory")
def inventory():
return {"reserved_items": params["items"]}
shipment = ctx.await_event(f"shipment.packed:{params['order_id']}")
@step("send-notification")
def notification():
return {
"sent_to": params["email"],
"tracking_number": shipment["tracking_number"],
}
return {
"order_id": params["order_id"],
"payment": payment,
"inventory": inventory,
"tracking_number": shipment["tracking_number"],
"notification": notification,
}
app.start_worker()
Asynchronous API
from absurd_sdk import AsyncAbsurd
app = AsyncAbsurd("postgresql://localhost/absurd")
@app.register_task(name="order-fulfillment")
async def process_order(params, ctx):
async def process_payment():
return {
"payment_id": f"pay-{params['order_id']}",
"amount": params["amount"],
}
payment = await ctx.step("process-payment", process_payment)
async def reserve_inventory():
return {"reserved_items": params["items"]}
inventory = await ctx.step("reserve-inventory", reserve_inventory)
shipment = await ctx.await_event(f"shipment.packed:{params['order_id']}")
async def send_notification():
return {
"sent_to": params["email"],
"tracking_number": shipment["tracking_number"],
}
notification = await ctx.step("send-notification", send_notification)
return {
"order_id": params["order_id"],
"payment": payment,
"inventory": inventory,
"tracking_number": shipment["tracking_number"],
"notification": notification,
}
await app.start_worker()