This is a collection of samples showing how to use the Temporal Python SDK with the experimental Trio async runtime.
These samples mirror the official samples-python but use Trio instead of asyncio.
Note: This is experimental and not production-ready. The Trio-based SDK is a proof of concept.
- uv
- Temporal CLI installed
- Local Temporal server running
- Rust toolchain (for building the Rust bridge)
The SDK requires Python >= 3.10.
This project depends on the experimental python-trio-sdk which includes a Rust bridge that must be built locally.
- Clone this repository alongside python-trio-sdk:
git clone https://github.com/mfateev/samples-python-trio
git clone https://github.com/mfateev/python-trio-sdk- Build the Rust bridge:
cd python-trio-sdk/temporalio_trio_bridge
# Requires maturin: pip install maturin
maturin build --release -o /tmp/wheels
cd ../..- Install samples dependencies:
cd samples-python-trio
uv sync
uv pip install /tmp/wheels/*.whl # Install the built bridgeThen start the Temporal server:
temporal server start-devAnd run a sample:
uv run hello/hello_activity.py-
Import from
temporalio_trioinstead oftemporaliofor workflow/worker:from temporalio_trio import workflow from temporalio_trio.worker import Worker
-
Use
trio.run()instead ofasyncio.run():if __name__ == "__main__": trio.run(main)
-
Use
trio.sleep()in the main function instead ofasyncio.sleep():await trio.sleep(1) # Outside workflow
-
Use
workflow.sleep()inside workflows (same as asyncio SDK):await workflow.sleep(1) # Inside workflow
- hello - Basic workflow and activity examples
- hello_activity - Execute an activity from a workflow
- hello_activity_async - Execute an async activity
- hello_activity_choice - Execute activities based on input
- hello_activity_heartbeat - Activity with heartbeat
- hello_activity_retry - Activity with retry policy
- hello_parallel_activity - Execute multiple activities (Trio nursery)
- hello_query - Query a workflow
The following samples from samples-python are not yet implemented due to missing features in the Trio SDK:
hello_activity_method- Requiresexecute_activity_methodhello_signal- Requiresworkflow.wait_conditionhello_child_workflow- Requiresexecute_child_workflowhello_continue_as_new- Requirescontinue_as_newhello_update- Requires@workflow.updatehello_patch- Requiresworkflow.patchedhello_local_activity- Requires local activity supporthello_search_attributes- Requires search attribute support
- python-trio-sdk - The experimental Trio-based Temporal SDK
- samples-python - Official asyncio samples