Skip to main content

ORCHER Python SDK

Crash-proof workflows, written as plain async Python.


PyPI Python versions CI Apache 2.0 docs

Write async functions; ORCHER journals each step and resumes interrupted runs where they stopped.

  • Durable: every step journaled; crashed runs resume on another worker
  • Plain Python: @workflow and @task on async functions, no DSL
  • Deterministic replay: step ids, time and randomness stay the same on every replay
  • Smart retries: per-task policies and never-retry error types
  • Timers and events: sleep for days or wait for an outside event
  • Child workflows: compose and run workflows in parallel
  • Actors: stateful objects with a single writer per key
  • Testing: run workflows in memory with mocks and a fake clock
  • Multi-tenant: API keys, organizations and namespaces built in
  • Native core: the engine protocol, replay and the worker run in Rust, shared with the Rust and TypeScript SDKs

Install

pip install orcher-sdk

The package installs as orcher:

import orcher

Quick start

Decorate a task and a workflow that calls it. Both register themselves when their module is imported, and the worker runs everything registered:

import asyncio
import os

from orcher import TaskContext, Worker, WorkflowContext, task, workflow


@task(name="send-confirmation", retry=3)
async def send_confirmation(ctx: TaskContext, order_id: str, email: str) -> str:
    return f"sent confirmation for {order_id} to {email}"


@workflow(name="confirm-order")
async def confirm_order(ctx: WorkflowContext, order_id: str, email: str) -> str:
    return await ctx.execute_task(send_confirmation, order_id=order_id, email=email)


async def main() -> None:
    worker = (
        Worker.builder()
        .server_url("http://localhost:50051")
        .namespace("default")
        .task_queue("orders")
        .api_key(os.environ.get("ORCHER_API_KEY"))  # for an engine that requires one
        .build()
    )
    await worker.run()


if __name__ == "__main__":
    asyncio.run(main())

Tasks that need clients or connections can be methods of a @tasks class instead; hand the worker a built instance with worker.register_task_instance().

Start it from any process and wait for the result. A dict input reaches the workflow as keyword arguments:

import os

from orcher import Client, ClientConfig

config = ClientConfig(
    server_url="http://localhost:50051",
    api_key=os.environ.get("ORCHER_API_KEY"),  # for an engine that requires one
)
async with Client(config) as client:
    handle = await client.start_workflow(
        "confirm-order",
        task_queue="orders",
        args=({"order_id": "order-1", "email": "ada@example.com"},),
    )
    receipt = await handle.result()

Guide

Timers: sleep for minutes or months

A timer is recorded by the engine, so no worker is busy while it runs, and a restart doesn't reset it:

from datetime import timedelta

from orcher import WorkflowContext, workflow


@workflow(name="trial")
async def trial(ctx: WorkflowContext, email: str) -> None:
    await ctx.sleep(timedelta(days=14))
    await ctx.execute_task(send_trial_ended, email=email)
Events: wait for something outside the workflow

A workflow can park until a named event arrives, optionally with a deadline:

from datetime import timedelta

from orcher import WorkflowContext, workflow


@workflow(name="approval")
async def approval(ctx: WorkflowContext, request_id: str) -> str:
    try:
        approved = await ctx.wait_for_event_with_timeout("approved", timedelta(days=3))
    except TimeoutError:
        return f"{request_id} expired"
    return f"{request_id} approved" if approved else f"{request_id} rejected"

Send the event from a client:

handle = await client.get_workflow("approval-42")
await handle.send_event("approved", True)

Cancel it the same way, optionally limiting how long its cleanup may take before the engine terminates it. Engines from before cancellation cleanup ignore the limit and cancel at once:

await handle.cancel(cleanup_timeout=timedelta(seconds=30))
Child workflows: compose workflows from workflows
from orcher import WorkflowContext, workflow


@workflow(name="ship-order")
async def ship_order(ctx: WorkflowContext, order_id: str) -> str:
    label = await ctx.execute_child_workflow("print-label", args=(order_id,))
    return f"{order_id} shipped with {label}"

ctx.start_child_workflow() returns a handle instead, to run several children at once and collect their results later.

Retries: decide which failures are worth retrying

A failure's type is the exception's class name (CardDeclined, not payments.CardDeclined). List the types never to retry in the task's policy. An exception whose non_retryable attribute is true is never retried, whatever the policy allows:

from orcher import RetryPolicy, TaskContext, task


class CardDeclined(Exception):
    pass


class AccountClosed(Exception):
    non_retryable = True


@task(
    name="charge",
    retry_policy=RetryPolicy(max_attempts=5, non_retryable_error_types=["CardDeclined"]),
)
async def charge(ctx: TaskContext, order_id: str) -> str:
    # Runs once:
    raise CardDeclined(f"card declined for {order_id}")
    # Also runs once, listed or not:
    # raise AccountClosed(f"account closed for {order_id}")

Any other exception is retried. non_retryable can also be set on a single instance before it is raised.

A workflow is marked the same way: an exception whose non_retryable attribute is true, raised from workflow code, fails the workflow without a retry, whatever its retry policy allows. Any other exception a workflow raises is retried as its policy says.

A workflow that catches the failure reads its type and whether the task was cancelled from the TaskError:

try:
    await ctx.execute_task(charge, order_id)
except TaskError as e:
    if e.is_cancelled:
        ...  # the task was cancelled
    elif e.error_type == "CardDeclined":
        ...  # ask for another card
Large payloads: what fits, and what happens when it doesn't

Workers and clients send and receive gRPC messages of up to 32 MiB; set ORCHER_MAX_MESSAGE_BYTES to change that. The engine accepts one payload (an input, a result, an event) of up to 8 MiB unless configured otherwise. A task whose result is too large fails straight away with a PayloadTooLarge failure that says how large it was, and is not retried: store large data elsewhere and pass a reference.

Encryption: keep payloads unreadable to the engine

Give the client and the worker a key and every payload is encrypted with AES-256-GCM just before it is sent to the engine and decrypted just after it arrives. The engine never holds the key: it stores ciphertext and returns it unchanged, so the values cannot be read in its database or its dashboard. Workflow, task and actor code sees plain values, as without encryption.

import os

from orcher import ClientConfig, Encryption, Worker

encryption = Encryption(
    key=bytes.fromhex(os.environ["PAYLOAD_KEY"]),  # exactly 32 bytes
    key_id="2026-11",
)

config = ClientConfig(server_url="http://localhost:50051", encryption=encryption)

worker = (
    Worker.builder()
    .server_url("http://localhost:50051")
    .task_queue("orders")
    .encryption(encryption)
    .build()
)

WorkerConfig takes the same encryption= and compression= as ClientConfig. Encryption.generate_key() makes a key; a key of any other length than 32 bytes is refused when the Encryption is made. Its repr never shows a key.

What is encrypted: workflow inputs and results, task inputs and results, step results, event payloads, query and update arguments and answers, child workflow inputs and results, actor calls and actor state.

What is not encrypted: names (of workflows, tasks, actors, events, queries and updates), ids, task queues, labels, annotations, headers, and error messages and stack traces. Keep secrets out of those, including out of the text of the exceptions your code raises. Encryption keeps payloads from the engine, not from your own processes: what your code logs, or a logging interceptor you add to the worker, is written in the clear.

To rotate a key, give the new one a new key_id and keep the old one for reading:

Encryption(
    key=new_key,
    key_id="2027-01",
    decryption_keys={"2026-11": old_key},
)

New payloads are written with the new key, and payloads that name an id in decryption_keys are still read, so workflows started before the rotation carry on. Only payloads written with a key_id name their key, so set one from the start. The id is stored unencrypted beside each payload and must not be derived from the key.

compression="gzip" (on ClientConfig and WorkerConfig, or .compression("gzip") on the builder) compresses payloads the same way, and needs the same setting everywhere. With both, a payload is compressed first and then encrypted. Payloads written before either was turned on stay readable afterwards.

Time and randomness: the replay-safe way

ctx.time reads the time the engine recorded, and ctx.random is seeded from the run, so both give the same answer every time the workflow is replayed:

from orcher import WorkflowContext, workflow


@workflow(name="invoice")
async def invoice(ctx: WorkflowContext, customer: str) -> str:
    number = ctx.random.uuid()
    issued_at = ctx.time.now()
    return f"invoice {number} for {customer}, issued at {issued_at.isoformat()}"
Testing: run workflows in memory

orcher.testing runs a workflow without an engine, with its tasks mocked by name. With pytest and pytest-asyncio:

import pytest

from orcher.testing import TestWorkflowEnvironment

from orders import confirm_order


@pytest.mark.asyncio
async def test_confirms_the_order() -> None:
    env = TestWorkflowEnvironment()
    env.mock_task("send-confirmation").returns("sent")

    receipt = await env.execute_workflow(
        confirm_order, {"order_id": "order-1", "email": "ada@example.com"}
    )

    assert receipt == "sent"
    env.assert_task_called_with(
        "send-confirmation", {"order_id": "order-1", "email": "ada@example.com"}
    )

Mocks can also raise, return a sequence or compute their result, and the environment controls the clock.

Workers: concurrency and stopping

A worker runs at most max_concurrent_workflows workflow activations, max_concurrent_tasks tasks and max_concurrent_actor_operations actor operations at once (set on the builder), and takes no more work from the engine while it is full. It hosts at most max_sessions sessions (10 unless set); a session creation that finds no free slot waits until its creation timeout, then fails. It registers with the engine when it starts, and the engine sees which SDK and release it runs.

await worker.shutdown() stops it taking work at once, and gives the work it is running the shutdown grace (shutdown_grace_time, 30 seconds unless set) to finish. Workflow activations still unfinished after that are handed back to the engine for another worker; tasks still running are asked to cancel (ctx.cancellation_token) and are retried once they time out. shutdown(force=True) cancels the running work without waiting for it.


Contributing

Issues and pull requests are welcome. See CONTRIBUTING.md for how to build, test and propose a change.

License

Licensed under the Apache License, Version 2.0.

"Python" and the Python logos are trademarks or registered trademarks of the Python Software Foundation, shown here to indicate the language this SDK is for.

Metadata

Release files for orcher-sdk 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for orcher-sdk 0.5.1
File Size Uploaded Provenance Actions
orcher_sdk-0.5.1.tar.gz 320.4 kB With provenance Details for orcher_sdk-0.5.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for orcher-sdk 0.5.1
File Actions
orcher_sdk-0.5.1-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details for orcher_sdk-0.5.1-cp311-abi3-musllinux_1_2_x86_64.whl
orcher_sdk-0.5.1-cp311-abi3-musllinux_1_2_aarch64.whl CPython 3.11 abi3 Linux musl 1.2+ ARM64 Details for orcher_sdk-0.5.1-cp311-abi3-musllinux_1_2_aarch64.whl
orcher_sdk-0.5.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for orcher_sdk-0.5.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
orcher_sdk-0.5.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for orcher_sdk-0.5.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
orcher_sdk-0.5.1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for orcher_sdk-0.5.1-cp311-abi3-macosx_11_0_arm64.whl
orcher_sdk-0.5.1-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for orcher_sdk-0.5.1-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 34.0 MB

Release files / orcher_sdk-0.5.1.tar.gz

Download URL orcher_sdk-0.5.1.tar.gz
Size 320.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8ff3e72522f173dcab54ba9ac1fc2724eee83189b959d5273774fc03f9c90c1a
BLAKE2b-256 checksum
How to use checksums
2b75690f7612c477a1730c04883e1091c106174b82f97b0b40c42130ffc5144c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / orcher_sdk-0.5.1-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL orcher_sdk-0.5.1-cp311-abi3-musllinux_1_2_x86_64.whl
Size 6.0 MB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
d7884fc0734fe3a9580e7d4336bc7b797b1dc92ba84b3138ada919b2dd5ac6b7
BLAKE2b-256 checksum
How to use checksums
dbab4a4d3d1372ede84226a436e912aa01d86c88d493fb6be461f2a22effb7fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / orcher_sdk-0.5.1-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL orcher_sdk-0.5.1-cp311-abi3-musllinux_1_2_aarch64.whl
Size 6.0 MB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
ebc8d80bbe92e146fd6714ebe7df1a1aa6b1c82d56d1035c2493f4b8c6a1ed78
BLAKE2b-256 checksum
How to use checksums
b2639323395b317819b4de5ccd873f5b11babeb8483c812991ca33e91f7b7f93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / orcher_sdk-0.5.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL orcher_sdk-0.5.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 5.6 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
8ea253ce6da0cbe6259fbb51338b94ac6472ebe0487570bdbe2b71773a34706c
BLAKE2b-256 checksum
How to use checksums
ebbda618db6d5106d1719ec541e9f3c28f8dd106241c5569a3e28b8d58741302
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / orcher_sdk-0.5.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL orcher_sdk-0.5.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 5.8 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
853e6537f5a63dc181a47597b66541c8bad30f7da2c2ad2f5b2967a41f0cd70e
BLAKE2b-256 checksum
How to use checksums
dcb3082e6b79b6b01712457a3115f2d1be1ebdbe6156098aa1f6da9686ceddc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / orcher_sdk-0.5.1-cp311-abi3-macosx_11_0_arm64.whl

Download URL orcher_sdk-0.5.1-cp311-abi3-macosx_11_0_arm64.whl
Size 5.1 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
729df7357aa34d9fcee9639139f8e585dc4d05d2ad9d9387a9874a4798b3074e
BLAKE2b-256 checksum
How to use checksums
fc71ca498260148c2fed86dced046e3f1cc52fbc89e3a3928ba4670db0e8494c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / orcher_sdk-0.5.1-cp311-abi3-macosx_10_12_x86_64.whl

Download URL orcher_sdk-0.5.1-cp311-abi3-macosx_10_12_x86_64.whl
Size 5.2 MB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
08b2fe91e7d8a298bc6c5c5a17a3e987400b053bd98cf0a9df6d4627889b2c2f
BLAKE2b-256 checksum
How to use checksums
492bc46b994a83df774d6a0fc59c16e8b683f5de5548e13272973e71c35eb63b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for orcher-sdk 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestation for orcher_sdk-0.5.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page