Documentation • Examples • Github • Discord
DBOS Transact is a Python library for ultra-lightweight durable execution. For example:
@DBOS.step()
def step_one():
...
@DBOS.step()
def step_two():
...
@DBOS.workflow()
def workflow()
step_one()
step_two()
Durable execution means your program is resilient to any failure. If it is ever interrupted or crashes, all your workflows will automatically resume from the last completed step. Durable execution helps solve many common problems:
- Orchestrating long-running or business-critical workflows so they seamlessly recover from any failure.
- Running reliable background jobs with no timeouts.
- Processing incoming events (e.g. from Kafka) exactly once.
- Running a fault-tolerant distributed task queue.
- Running a reliable cron scheduler.
- Operating an AI agent, or anything that connects to an unreliable or non-deterministic API.
What’s unique about DBOS's implementation of durable execution is that it’s implemented in a lightweight library that’s totally backed by Postgres.
To use DBOS, just pip install
it and annotate your program with DBOS decorators.
Under the hood, those decorators store your program's execution state (which workflows are currently executing and which steps they've completed) in a Postgres database.
If your program crashes or is interrupted, they automatically recover its workflows from their stored state.
So all you need to use DBOS is Postgres—there are no other dependencies you have to manage, no separate workflow server.
One big advantage of this approach is that you can add DBOS to any Python application—it’s just a library. You can use DBOS to add reliable background jobs or cron scheduling or queues to your app with no external dependencies except Postgres.
Install and configure with:
pip install dbos
dbos init --config
Then, try it out with this simple program:
from fastapi import FastAPI
from dbos import DBOS
app = FastAPI()
DBOS(fastapi=app)
@DBOS.step()
def step_one():
print("Step one completed!")
@DBOS.step()
def step_two():
print("Step two completed!")
@DBOS.workflow()
def dbos_workflow():
step_one()
for _ in range(5):
print("Press Control + \ to stop the app...")
DBOS.sleep(1)
step_two()
@app.get("/")
def fastapi_endpoint():
dbos_workflow()
Save the program into main.py
and start it with fastapi run
.
Visit localhost:8000
in your browser to start the workflow.
When prompted, press Control + \
to force quit your application.
It should crash midway through the workflow, having completed step one but not step two.
Then, restart your app with fastapi run
.
It should resume the workflow from where it left off, completing step two without re-executing step one.
To learn how to build more complex workflows, see the programming guide or examples.
- AI-Powered Slackbot — A Slackbot that answers questions about previous Slack conversations, using DBOS to durably orchestrate its RAG pipeline.
- Widget Store — An online storefront that uses DBOS durable workflows to be resilient to any failure.
- Scheduled Reminders — In just three lines of code, schedule an email to send days, weeks, or months in the future.
More examples here!
If you're interested in building with us, please star our repository and join our community on Discord! If you see a bug or have a feature request, don't hesitate to open an issue here on GitHub. If you're interested in contributing, check out our contributions guide.