Skip to main content

Strait Python SDK

Project description

Strait

Python SDK for the Strait API

CI PyPI Python License Types


The official Python SDK for Strait -- an open-source job execution and workflow orchestration platform for humans and AI agents. Define jobs, build DAG workflows, run durable AI agents with cost tracking, and manage the full run lifecycle from Python.

Sync and async clients, 19 domain services (~186 operations), authoring DSL, composition helpers, FSM state machines, and PEP 561 type hints.

Website | Platform Repo | Documentation | PyPI

Installation

pip install strait-python

Requires Python 3.11+.

Quick Start

from strait import Client

client = Client(base_url="https://api.strait.dev", api_key="your-key")

# List jobs
jobs = client.jobs.list()

# Trigger a job
run = client.jobs.trigger(job["id"], {"payload": {"key": "value"}})

# Get a run
run = client.runs.get(run["id"])

Async

from strait import AsyncClient

async with AsyncClient.from_env() as client:
    jobs = await client.jobs.list()
    run = await client.jobs.trigger("job-id", {"payload": {}})

Configuration

Three ways to create a client:

# From environment variables (STRAIT_BASE_URL, STRAIT_API_KEY)
client = Client.from_env()

# From strait.json file (token always from STRAIT_API_KEY env var)
client = Client.from_file()

# Inline
client = Client(base_url="https://api.strait.dev", api_key="your-key")

All methods work with AsyncClient too. See Configuration Guide for details.

Features

Domain Operations (19 Services)

All 186 API operations organized into typed service classes:

Service Examples
client.jobs list, create, get, update, delete, trigger, bulk_trigger
client.runs list, get, delete, replay, bulk_cancel, get_dlq
client.workflows list, create, trigger, get_diff, get_policy
client.workflow_runs list, pause, resume, approve_step, skip_step
client.deployments list, create, finalize, promote, rollback
client.sdk_runs complete_run, heartbeat_run, checkpoint_run
client.rbac list_roles, create_member, seed_roles
+ 12 more environments, secrets, api_keys, webhooks, ...

Authoring DSL

Define jobs, workflows, and AI agents with a type-safe DSL:

from strait.authoring import define_job, define_workflow, JobOptions, WorkflowOptions
from strait.authoring import job_step, approval_step

wf = define_workflow(WorkflowOptions(
    name="Order Pipeline", slug="order-pipeline", project_id="proj-1",
    steps=[
        job_step("validate", "validate-job"),
        job_step("charge", "charge-job", depends_on=["validate"]),
        approval_step("approve", depends_on=["charge"]),
        job_step("ship", "ship-job", depends_on=["approve"]),
    ],
))

See Authoring Guide for AI agents, event definitions, RunContext, and test harness.

Composition Helpers

from strait.composition import with_retry, wait_for_run, paginate, RetryOptions

# Retry with exponential backoff
result = with_retry(lambda: client.jobs.trigger("j1", payload), RetryOptions(attempts=5))

# Wait for a run to complete
run = wait_for_run(
    get_run=lambda rid: client.runs.get(rid),
    get_status=lambda r: r["status"],
    run_id="run-1",
)

See Composition Guide for cost budgets, checkpoint resume, pagination, and more.

Error Handling

All errors inherit from StraitError with typed exceptions for each HTTP status:

from strait import NotFoundError, RateLimitedError

try:
    job = client.jobs.get("nonexistent")
except NotFoundError as e:
    print(f"Not found: {e} (status={e.status})")
except RateLimitedError as e:
    print(f"Rate limited, retry after backoff")

See Error Handling Guide for the full exception hierarchy.

Middleware

from strait import Client, Middleware

mw = Middleware(
    on_request=lambda ctx: print(f"-> {ctx.method} {ctx.url}"),
    on_response=lambda ctx: print(f"<- {ctx.status} ({ctx.duration_ms}ms)"),
)
client = Client.from_env(middleware=[mw])

FSM State Machines

from strait.fsm import transition_run, RunStatus, RunEvent

next_status = transition_run(RunStatus.EXECUTING, RunEvent.COMPLETE)
assert next_status == RunStatus.COMPLETED

Documentation

Guide Description
Configuration Client creation, auth types, strait.json, env vars
Authoring Jobs, workflows, agents, RunContext, test harness
Composition Retry, wait, paginate, cost budget, checkpoint resume
Errors Exception hierarchy, HTTP error mapping
Examples Runnable code examples for all major features

Development

make bootstrap   # Create venv + install deps
make lint        # Run ruff (lint + format check)
make typecheck   # Run mypy (strict mode)
make test        # Run pytest with coverage
make run-all     # lint + typecheck + test

See CONTRIBUTING.md for the full contributor guide.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

strait_python-0.1.1.tar.gz (46.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

strait_python-0.1.1-py3-none-any.whl (56.5 kB view details)

Uploaded Python 3

File details

Details for the file strait_python-0.1.1.tar.gz.

File metadata

  • Download URL: strait_python-0.1.1.tar.gz
  • Upload date:
  • Size: 46.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for strait_python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7dbb4577be57684d821f0bb7fb51b42aa6d040ac3cf3fc37fd859378d3f71316
MD5 e867ab7560edba8997d0c8eccccfc348
BLAKE2b-256 c508724ddad430320b51caacf33dda7cabfa30faa61310d0f601a980f47704b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for strait_python-0.1.1.tar.gz:

Publisher: publish.yml on strait-dev/strait-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file strait_python-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: strait_python-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 56.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for strait_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b9564758df9f31e316ea4f0e0507bcaf8ce33976e2c96eef64f1ce113aa617fe
MD5 d9259390c5883582d3aac2f887cf118e
BLAKE2b-256 d42b3d8981a6c884ebea02b889c66c6916886ecc506438ad073571d472d546da

See more details on using hashes here.

Provenance

The following attestation bundles were made for strait_python-0.1.1-py3-none-any.whl:

Publisher: publish.yml on strait-dev/strait-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page