Skip to main content

PyPI Version Python Version GitHub License

Test Lint

durable-python

Make Python async functions durable and resumable with a minimal, pluggable runtime.

Overview

durable-python

This package treats durability as a core runtime concern. Async functions are transformed into a sequence of CodeBlocks that can be checkpointed, paused, and resumed through a DurableRuntime. Everything is open and pluggable: orchestration backends implement a small interface, and persistence is provided through StateStore implementations.

Key primitives:

  • DurableRuntime — drives execution and persistence.
  • CallStack / FunctionCall / CodeBlock — durable execution model.
  • OrchestrationBackend / DurableBackend — orchestration + event waiting.
  • StateStore / InMemoryStateStore / DiskStateStore — persistence.
  • DurableAstTransformer / make_durable — transform async functions into durable programs.

Quick Start

import asyncio
from durable import DurableBackend, InMemoryStateStore, PauseForEventException, make_durable

# Define your async function
async def greet(name: str):
    print("waiting for permission to greet")
    raise PauseForEventException("allow")
    return f"hello {name}"

# Make it durable
durable_greet = make_durable(greet)

async def main():
    backend = DurableBackend(InMemoryStateStore())

    async def run_once():
        # Triggers runtime execution; will pause on PauseForEventException
        try:
            return await durable_greet("Ada", orchestration_backend=backend, instance_id="greet-1")
        except PauseForEventException as e:
            print(f"paused for event {e.event}")

    await run_once()                 # pauses and persists state
    backend.publish_event("greet-1", "allow")  # deliver event
    result = await durable_greet("Ada", orchestration_backend=backend, instance_id="greet-1")
    print(result)                    # "hello Ada"

asyncio.run(main())

Architecture

  • Execution model: FunctionCall holds locals, an ordered list of CodeBlocks, and the current index. CallStack orchestrates nested calls and return propagation.
  • Durable runtime: DurableRuntime restores saved state (if any), drives the call stack, and delegates persistence plus event waiting to an OrchestrationBackend.
  • Backends: OrchestrationBackend defines load_state, save_state, and wait_for_event. DurableBackend is the OSS implementation backed by a StateStore and an in-memory event bus.
  • Persistence: StateStore defines load / save. The OSS package ships InMemoryStateStore and DiskStateStore(path).
  • Transformation: DurableAstTransformer rewrites async functions into checkpointable code. make_durable(fn) wraps a function into a DurableProgram that builds a runtime and executes it.

Custom Backends

Implement OrchestrationBackend to integrate with your own orchestration layer:

from durable import OrchestrationBackend

class CustomBackend(OrchestrationBackend):
    async def load_state(self, instance_id: str) -> dict | None:
        ...

    async def save_state(self, instance_id: str, state: dict) -> None:
        ...

    async def wait_for_event(self, instance_id: str, event_name: str) -> None:
        ...

Use it by passing orchestration_backend= to the callable returned by make_durable.

Testing

Install dev dependencies and run pytest:

poetry install --with dev
poetry run pytest

Metadata

Release files for durable-python 0.1.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 durable-python 0.1.1
File Size Uploaded
durable_python-0.1.1.tar.gz 14.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for durable-python 0.1.1
File Interpreter ABI Platform
durable_python-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 30.2 kB

Release files / durable_python-0.1.1.tar.gz

Download URL durable_python-0.1.1.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0f58caf4b8da316fb36f5e618dcee77f7745900adef8fbce7defb60a0e5ca73b
BLAKE2b-256 checksum
How to use checksums
f53a8b6920aff098c89b1fc06c127f3b821c25913a02102de118bedfbea5b529
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.13.5 Darwin/24.3.0

Release files / durable_python-0.1.1-py3-none-any.whl

Download URL durable_python-0.1.1-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79521aba63bbe7540460ab9117bc2d07c632c4f0a09446294d75f19be56f7777
BLAKE2b-256 checksum
How to use checksums
3d0e60712b68bad5b99454a613c8f9dc0cd92d5bb9f98caadf5486c53db835a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.13.5 Darwin/24.3.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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