Profile
Back to NewsBack
GitHub Trending 6 min
Reader Mode
temporalio/samples-python: Samples for working with the Temporal Python SDK

temporalio/samples-python: Samples for working with the Temporal Python SDK

12 hours ago

Temporal Python SDK Samples

This is a collection of samples showing how to use the Python SDK.

Usage

Prerequisites:

temporal server start-dev

The SDK requires Python >= 3.10. You can install Python using uv. For example,

uv python install 3.13

With this repository cloned, run the following at the root of the directory:

uv sync

That loads all required dependencies. Then to run a sample, usually you just run it under uv. For example:

uv run hello/hello_activity.py

Some examples require extra dependencies. See each sample's directory for specific instructions.

Samples

  • hello - All of the basic features.
* hello_activity - Execute an activity from a workflow. * hello_activity_choice - Execute certain activities inside a workflow based on dynamic input. * hello_activity_method - Demonstrate an activity that is an instance method on a class and can access class state. * hello_activity_multiprocess - Execute a synchronous activity on a process pool. * hello_activity_retry - Demonstrate activity retry by failing until a certain number of attempts. * hello_activity_threaded - Execute a synchronous activity on a thread pool. * hello_async_activity_completion - Complete an activity outside of the function that was called. * hello_cancellation - Manually react to cancellation inside workflows and activities. * hello_change_log_level - Change the level of workflow task failure from WARN to ERROR. * hello_child_workflow - Execute a child workflow from a workflow. * hello_continue_as_new - Use continue as new to restart a workflow. * hello_cron - Execute a workflow once a minute. * hello_exception - Execute an activity that raises an error out of the workflow and out of the program. * hello_local_activity - Execute a local activity from a workflow. * hello_mtls - Accept URL, namespace, and certificate info as CLI args and use mTLS for connecting to server. * hello_parallel_activity - Execute multiple activities at once. * hello_query - Invoke queries on a workflow. * hello_search_attributes - Start workflow with search attributes then change while running. * hello_signal - Send signals to a workflow. * hello update - Send a request to and a response from a client to a workflow execution. This contains two samples, one sending messages to an existing workflow and a second that creates a workflow through Nexus and sends messages to it. This version uses @nexus.temporal_operation to allow Nexus operation handlers to either return a synchronous result or start a Workflow as the async backing operation. without wrapping them in a workflow.
  • open_telemetry - Trace workflows with OpenTelemetry.
  • openai_agents - Run OpenAI Agents SDK agents as durable Temporal workflows.
  • openrouter - Call OpenRouter from Activities: fan out a prompt batch, and pause instead of failing when the budget or credits run out.
  • patching - Alter workflows safely with patch and deprecate_patch.
  • polling - Recommended implementation of an activity that needs to periodically poll an external resource waiting its successful completion.
  • prometheus - Configure Prometheus metrics on clients/workers.
  • pydantic_converter - Data converter for using Pydantic models.
  • pydantic_converter_v1 - Data converter for Pydantic v1 models (prefer pydantic_converter for v2).
  • replay - Verify that workflow code changes are compatible with existing histories.
  • resource_pool - Allocate a pool of shared resources across workflows.
  • schedules - Demonstrates a Workflow Execution that occurs according to a schedule.
  • sentry - Report errors to Sentry.
  • sleep_for_days - A workflow that runs forever, sending an email every 30 days.
  • strands_plugin - Run Strands Agents as durable Temporal workflows (model calls, tools, MCP, HITL).
  • trio_async - Use asyncio Temporal in Trio-based environments.
  • updatable_timer - A timer that can be updated while sleeping.
  • worker_multiprocessing - Leverage Python multiprocessing to parallelize workflow tasks and other CPU bound operations by running multiple workers.
  • worker_specific_task_queues - Use unique task queues to ensure activities run on specific workers.
  • worker_versioning - Use the Worker Versioning feature to more easily version your workflows & other code.
  • workflow_streams - Workflow-hosted durable event stream via temporalio.contrib.workflow_streams. Experimental

Test

To run the tests:

uv run poe test

Chat with me