Temporal Workflow Python

Published
Length
3 min read

Luis Felipe Dias

All posts

You build a temporal workflow python system by defining workflow logic and external tasks separately. A central server tracks every step while your Python workers run the actual code. Teams often give these workers broad database roles to get apps running fast. Broad roles let one bad task update or read sensitive tables by mistake. How a temporal workflow python architecture runs Temporal splits your code into two main parts called workflows and activities. Workflows hold the deterministic s

Agentic Workflow Security: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You build a temporal workflow python system by defining workflow logic and external tasks separately. A central server tracks every step while your Python workers run the actual code. Teams often give these workers broad database roles to get apps running fast. Broad roles let one bad task update or read sensitive tables by mistake.

How a temporal workflow python architecture runs

Temporal splits your code into two main parts called workflows and activities. Workflows hold the deterministic step-by-step rules for your business process. They cannot call external APIs, read local files, or query databases directly. This strict rule lets the server replay history and recover state after crashes.

Activities handle all outside work like sending emails or writing to a database. When a workflow needs outside data, it schedules an activity task on a queue. The central server holds that task in the queue until a worker takes it. If an activity fails, the server retries it based on your retry rules.

Python workers are processes that you host on your own servers or containers. These workers poll the central task queues and run your Python functions. Because workers execute activities, they hold the keys for your databases and APIs. You scale your app by running more worker processes to poll the same queues.

Managing worker permissions and data payloads

Workers need network routes and keys to reach the central server and your databases. Teams use mutual TLS certificates or API keys so workers can log in. Namespace rules in the server isolate one team from another team's task queues. This native setup controls which worker process can poll a specific queue.

Still, namespace rules only check which worker logs into the central server. They do not inspect the SQL queries or API calls that activities run later. When an activity runs, it uses the static database role given to that worker. A bug in Python code can still run a broad query or drop rows.

Payload storage is another key area that requires careful planning from your team. The central server logs every input and output from your activities in its database. If an activity returns customer emails or card numbers, the server stores that data. Teams use custom data converters in Python to encrypt payloads before sending them out.

Agentic Workflow Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why native worker roles leave an operational gap

Encrypting payloads protects data at rest inside the central workflow history tables. Role checks on namespaces keep unauthorized workers off your production task queues. Yet both tools stop at the edge of the workflow engine itself. They do not govern how workers interact with your actual production data stores.

In most setups, every Python worker shares one powerful database login key. Engineers debugging a failed workflow often need to inspect the same target databases. Giving developers or workers full database roles creates a major security risk. Native workflow settings decide who starts a job, not what queries run in flight.

To close this gap, teams must control database sessions at the query level. You need a way to check every command before the database runs it. Masking fields like phone numbers or national IDs in results also reduces exposure. Separating workflow orchestration from direct database keys keeps both automated jobs and human sessions safe.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Why must Python workflow code stay deterministic?

The server recovers state by replaying your workflow code from the very first event. If the code produces different paths during replay, the server cannot match past events. Keep all random numbers, system clocks, and network calls inside activities instead.

Where do database calls belong in a Temporal Python app?

Put all database reads and writes inside activity functions, never inside workflow functions. Activities can fail, time out, and retry safely without breaking the workflow replay history. The server records the final activity result once so replays skip the database call.

How do teams protect sensitive data in workflow histories?

Teams configure a custom payload codec in the Python worker before starting it. The worker encrypts arguments and results locally before sending them to the central server. Only workers or UI tools with the matching encryption key can read those payloads.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.