Skip to content

mfateev/samples-python-trio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Temporal Python SDK Samples (Trio)

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.

Prerequisites

The SDK requires Python >= 3.10.

Usage

This project depends on the experimental python-trio-sdk which includes a Rust bridge that must be built locally.

Setup

  1. 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
  1. Build the Rust bridge:
cd python-trio-sdk/temporalio_trio_bridge
# Requires maturin: pip install maturin
maturin build --release -o /tmp/wheels
cd ../..
  1. Install samples dependencies:
cd samples-python-trio
uv sync
uv pip install /tmp/wheels/*.whl  # Install the built bridge

Then start the Temporal server:

temporal server start-dev

And run a sample:

uv run hello/hello_activity.py

Key Differences from asyncio Samples

  1. Import from temporalio_trio instead of temporalio for workflow/worker:

    from temporalio_trio import workflow
    from temporalio_trio.worker import Worker
  2. Use trio.run() instead of asyncio.run():

    if __name__ == "__main__":
        trio.run(main)
  3. Use trio.sleep() in the main function instead of asyncio.sleep():

    await trio.sleep(1)  # Outside workflow
  4. Use workflow.sleep() inside workflows (same as asyncio SDK):

    await workflow.sleep(1)  # Inside workflow

Samples

Not Yet Implemented

The following samples from samples-python are not yet implemented due to missing features in the Trio SDK:

  • hello_activity_method - Requires execute_activity_method
  • hello_signal - Requires workflow.wait_condition
  • hello_child_workflow - Requires execute_child_workflow
  • hello_continue_as_new - Requires continue_as_new
  • hello_update - Requires @workflow.update
  • hello_patch - Requires workflow.patched
  • hello_local_activity - Requires local activity support
  • hello_search_attributes - Requires search attribute support

Related Projects

About

Temporal Python SDK samples using Trio async runtime

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages