Skip to main content

Run your first Temporal application with the Python SDK

You can think of Temporal as a sort of "cure-all" for the pains you experience as a developer when trying to build reliable applications. Whether you're writing a complex transaction-based Workflow or working with remote APIs, you know that creating reliable applications is a complex process.

Temporal beginner
Part 1: Build Your First Workflow
Part 2: Failure Simulation

Introduction

In this tutorial, you'll build and run your first Temporal Application. You'll learn how to construct Workflows and Activities, understand the core building blocks, and see you can get full visibility into its execution.

Prerequisites

Before starting this tutorial:

  • Set up a local development environment for developing Temporal Applications using the Python programming language
  • Ensure you have Git installed to clone the project

Quickstart Guide

Run through the Quickstart to get your set up complete.

What You'll Build

You'll construct a money transfer application from the ground up, learning to design and implement essential transactions such as withdrawals, deposits, and refunds using Temporal's powerful building blocks.

Why This Application? It demonstrates real-world complexity while teaching you how to build reliable, fault-tolerant systems that handle money safely.

Money Transfer Application Flow

In this sample application, money comes out of one account and goes into another. However, there are a few things that can go wrong with this process. If the withdrawal fails, then there is no need to try to make a deposit. But if the withdrawal succeeds, but the deposit fails, then the money needs to go back to the original account.

One of Temporal's most important features is its ability to maintain the application state when something fails. When failures happen, Temporal recovers processes where they left off or rolls them back correctly. This allows you to focus on business logic, instead of writing application code to recover from failure.

Download the example application

The application you'll use in this tutorial is available in a GitHub repository.

Open a new terminal window and use git to clone the repository, then change to the project directory.

Now that you've downloaded the project, let's dive into the code.

git clone https://github.com/temporalio/money-transfer-project-template-python cd money-transfer-project-template-python
tip

The repository for this tutorial is a GitHub Template repository, which means you could clone it to your own account and use it as the foundation for your own Temporal application.

Let's Recap: Temporal's Application Structure

The Temporal Application will consist of the following pieces:

  1. A Workflow written in Python using the Python SDK. A Workflow defines the overall flow of the application.
  2. An Activity is a method that encapsulates business logic prone to failure (e.g., calling a service that may go down). These Activities can be automatically retried upon some failure. They handle individual tasks like withdraw(), deposit(), and refund().
  3. A Worker, provided by the Temporal SDK, which runs your Workflow and Activities reliably and consistently.
Temporal Application Components
Your Temporal Application
info

None of your application code runs on the Temporal Server. Your Worker, Workflow, and Activity run on your infrastructure, along with the rest of your applications.

Build your Workflow and Activities

Go example coming soon.

Set the Retry Policy

Temporal makes your software durable and fault tolerant by default. If an Activity fails, Temporal automatically retries it, but you can customize this behavior through a Retry Policy.

In the MoneyTransfer Workflow, you'll see a Retry Policy that retries failed Activities up to 3 times, with specific errors that shouldn't be retried:

retry_policy = RetryPolicy(
maximum_attempts=3,
maximum_interval=timedelta(seconds=2),
non_retryable_error_types=["InvalidAccountError", "InsufficientFundsError"],
)
This is a Simplified Example

This tutorial shows core Temporal features and is not intended for production use. A real money transfer system would need additional logic for edge cases, cancellations, and error handling.

Run Your Money Transfer

Now that your Worker is running and polling for tasks, you can start a Workflow Execution.

In Terminal 3, start the Workflow:

The run_workflow.py script starts a Workflow Execution. Each time you run this file, the Temporal Server starts a new Workflow Execution.

Workflow Status: EXECUTING
Withdraw Activity: RUNNING
Deposit Activity: RUNNING
Transaction: COMPLETED
Terminal 1 - Start the Temporal server:
temporal server start-dev
Terminal 2 - Start the Worker:
python run_worker.py
Terminal 3 - Start the Workflow:
python run_workflow.py
Expected Success Output:
Result: Transfer complete (transaction IDs: Withdrew $250 from account 85-150. ReferenceId: 12345, Deposited $250 into account 43-812. ReferenceId: 12345)

Check the Temporal Web UI

The Temporal Web UI lets you see details about the Workflow you just ran.

What you'll see in the UI:

  • List of Workflows with their execution status
  • Workflow summary with input and result
  • History tab showing all events in chronological order
  • Query, Signal, and Update capabilities
  • Stack Trace tab for debugging

Try This: Click on a Workflow in the list to see all the details of the Workflow Execution.

Money Transfer Web UI

Ready for Part 2?

Continue to Part 2: Simulate Failures

Simulate crashes, fix bugs in running workflows, and experience Temporal's reliability superpowers

Continue Your Learning