Learn DBOS Python
This guide shows you how to use DBOS to build Python apps that are resilient to any failure.
1. Setting Up Your Environment
Create a folder for your app with a virtual environment, then enter the folder and activate the virtual environment.
- macOS or Linux
- Windows (PowerShell)
- Windows (cmd)
python3 -m venv dbos-starter/.venv
cd dbos-starter
source .venv/bin/activate
python3 -m venv dbos-starter/.venv
cd dbos-starter
.venv\Scripts\activate.ps1
python3 -m venv dbos-starter/.venv
cd dbos-starter
.venv\Scripts\activate.bat
Then, install DBOS:
pip install dbos
2. Workflows and Steps
DBOS helps you add reliability to your Python programs. The key feature of DBOS is workflow functions comprised of steps. DBOS checkpoints the state of your workflows and steps to its system database. If your program crashes or is interrupted, DBOS uses this checkpointed state to recover each of your workflows from its last completed step. Thus, DBOS makes your application resilient to any failure.
DBOS uses a database to durably store workflow and step state.
By default, it uses SQLite, which requires no configuration.
For production use, we recommend connecting your DBOS application to a Postgres database.
You can optionally run these examples with Postgres by setting the DBOS_SYSTEM_DATABASE_URL environment variable to a connection string to your Postgres database.
Let's create a simple DBOS program that runs a workflow of two steps.
Create main.py and add this code to it:
import os
from dbos import DBOS, DBOSConfig
@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()
step_two()
if __name__ == "__main__":
config: DBOSConfig = {
"name": "dbos-starter",