Skip to main content
The Omium Python SDK provides two ways to integrate:
  1. Auto-Instrumentation (Recommended) - Automatically captures traces and checkpoints
  2. Manual API - Explicit control over checkpoints and tracing

Installation

pip install omium

The simplest way to use Omium. One-time setup, then your existing code works unchanged.

Initialize

import omium

# Option 1: With API key directly
omium.init(api_key="om_xxx")

# Option 2: Load from config file (~/.omium/config.json)
omium.init()  # Uses saved config from 'omium init' CLI

Instrument LangGraph

import omium

omium.init(api_key="om_xxx")
omium.instrument_langgraph()  # Enables auto-tracing

from langgraph.graph import StateGraph

# Your LangGraph code - traces captured automatically
graph = StateGraph(MyState)
# ... build graph
app = graph.compile()
result = app.invoke({"input": "Hello"})

Instrument CrewAI

import omium

omium.init(api_key="om_xxx")
omium.instrument_crewai()  # Enables auto-tracing

from crewai import Crew, Agent, Task

# Your CrewAI code - traces captured automatically
crew = Crew(agents=[...], tasks=[...])
result = crew.kickoff()

Manual Tracing

For explicit control over what gets traced.

@trace Decorator

import omium

omium.init(api_key="om_xxx")

@omium.trace("process_data")
def process_data(data: dict):
    # Function execution is traced
    return {"processed": data}

@omium.trace("analyze_result")  
async def analyze_result(data: dict):
    # Works with async functions too
    return {"analysis": "complete"}

@checkpoint Decorator

import omium

omium.init(api_key="om_xxx")

@omium.checkpoint("important_step")
def important_step(data: dict):
    # Creates checkpoint before execution
    # Can recover from here if later steps fail
    return expensive_operation(data)

Callback Handler

For LangChain-style callback integration:
from omium import OmiumCallbackHandler

handler = OmiumCallbackHandler()

# Use with LangChain
chain.invoke(input_data, config={"callbacks": [handler]})

# Use with LangGraph
app.invoke(input_data, config={"callbacks": [handler]})

OmiumClient API

For direct checkpoint management:
from omium import OmiumClient

client = OmiumClient()
await client.connect()

# Create checkpoint
checkpoint = await client.create_checkpoint(
    checkpoint_name="after_data_load",
    state={"data": my_data},
    execution_id="exec-123",
    metadata={"step": 1}
)

# Get checkpoint
checkpoint = await client.get_checkpoint(
    checkpoint_id="cp-456",
    include_state=True
)

# List checkpoints
checkpoints = await client.list_checkpoints(
    execution_id="exec-123",
    limit=10
)

await client.close()

OmiumClient Methods

MethodDescription
connect()Establish connection to Omium services
close()Close connection
create_checkpoint()Create a new checkpoint
get_checkpoint()Retrieve a checkpoint by ID
list_checkpoints()List checkpoints for an execution
set_execution_context()Set default execution/agent context

Configuration

OmiumConfig

from omium import OmiumConfig

config = OmiumConfig(
    api_key="om_xxx",
    api_url="https://api.omium.ai",
    auto_checkpoint=True,
    checkpoint_interval=10  # seconds
)

omium.configure(config)

Config File

The CLI stores config in ~/.omium/config.json:
{
  "api_key": "om_xxx",
  "api_url": "https://api.omium.ai/api/v1",
  "region": "us-east-1"
}

Exceptions

from omium import (
    CheckpointError,
    CheckpointNotFoundError,
    CheckpointValidationError,
    ConnectionError
)

try:
    await client.get_checkpoint("invalid-id")
except CheckpointNotFoundError:
    print("Checkpoint not found")
except CheckpointError as e:
    print(f"Checkpoint error: {e}")
except ConnectionError as e:
    print(f"Connection failed: {e}")

Next Steps