0% found this document useful (0 votes)
6 views

Child Workflows - Python SDK | Temporal Platform Documentation

The document provides guidance on using the Temporal Python SDK to start Child Workflow Executions and set Parent Close Policies. It explains how to initiate a Child Workflow, ensuring it has started before proceeding, and discusses the default behavior when a Parent Workflow closes. Additionally, it includes code examples for implementing these functionalities within workflows.

Uploaded by

pine147miren
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Child Workflows - Python SDK | Temporal Platform Documentation

The document provides guidance on using the Temporal Python SDK to start Child Workflow Executions and set Parent Close Policies. It explains how to initiate a Child Workflow, ensuring it has started before proceeding, and discusses the default behavior when a Parent Workflow closes. Additionally, it includes code examples for implementing these functionalities within workflows.

Uploaded by

pine147miren
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Child Workflows - Python SDK | Temporal Platform Documentation 10.04.

2025, 17:09

Develop

Python SDK Child Workflows

Child Workflows - Python


SDK
This page shows how to do the
following:

Start a Child Workflow


Execution
Set a Parent Close Policy

Start a Child
Workflow
Execution
How to start a Child Workflow
Execution using the Temporal
Python SDK.

A Child Workflow Execution is a


Workflow Execution that is
scheduled from within another
Workflow using a Child Workflow
API.

When using a Child Workflow API,


Child Workflow related Events
(StartChildWorkflowExecutionInitiate
d, ChildWorkflowExecutionStarted,
ChildWorkflowExecutionCompleted, Ask AI
etc...) are logged in the Workflow

https://docs.temporal.io/develop/python/child-workflows Page 1 of 6
Child Workflows - Python SDK | Temporal Platform Documentation 10.04.2025, 17:09

Execution Event History.

Always block progress until the


ChildWorkflowExecutionStarted
Event is logged to the Event History
to ensure the Child Workflow
Execution has started. After that,
Child Workflow Executions may be
abandoned using the Abandon
Parent Close Policy set in the Child
Workflow Options.

To be sure that the Child Workflow


Execution has started, first call the
Child Workflow Execution method on
the instance of Child Workflow
future, which returns a different
future.

Then get the value of an object that


acts as a proxy for a result that is
initially unknown, which is what
waits until the Child Workflow
Execution has spawned.

To spawn a Child Workflow


Execution in Python, use the
execute_child_workflow()
function which starts the Child
Workflow and waits for completion
or use the
start_child_workflow()
function to start a Child Workflow
and return its handle. This is useful if
you want to do something after it
has only started, or to get the

https://docs.temporal.io/develop/python/child-workflows Page 2 of 6
Child Workflows - Python SDK | Temporal Platform Documentation 10.04.2025, 17:09

Workflow/Run ID, or to be able to


signal it while running.

NOTE

execute_child_workflow()
is a helper function for
start_child_workflow()
plus await handle .

View the in the context of the


source rest of the application
code code.

# ...
@workflow.defn
class ComposeGreetingWorkflow
@workflow.run
async def run(self, input
ComposeGreetingInput) -> str
return f"
{input.greeting}, {input.name

@workflow.defn
class GreetingWorkflow:
@workflow.run
async def run(self, name
str) -> str:
return await
workflow.execute_child_workflow

ComposeGreetingWorkflow.run,

ComposeGreetingInput("Hello"
name),
id="hello-child-

https://docs.temporal.io/develop/python/child-workflows Page 3 of 6
Child Workflows - Python SDK | Temporal Platform Documentation 10.04.2025, 17:09

workflow-workflow-child-id",
# ...
)

Set a Parent Close


Policy
How to set a Parent Close Policy

A Parent Close Policy determines


what happens to a Child Workflow
Execution if its Parent changes to a
Closed status (Completed, Failed, or
Timed Out).

The default Parent Close Policy


option is set to terminate the Child
Workflow Execution.

Set the parent_close_policy


parameter inside the
start_child_workflow function
or the
execute_child_workflow()
function to specify the behavior of
the Child Workflow when the Parent
Workflow closes.

View the in the context of the


source rest of the application
code code.

from temporalio.workflow import


ParentClosePolicy

https://docs.temporal.io/develop/python/child-workflows Page 4 of 6
Child Workflows - Python SDK | Temporal Platform Documentation 10.04.2025, 17:09

# ...
# ...
@workflow.defn
class ComposeGreetingWorkflow
@workflow.run
async def run(self, input
ComposeGreetingInput) -> str
return f"{input.greeting
{input.name}!"

@workflow.defn
class GreetingWorkflow:
@workflow.run
async def run(self, name
return await
workflow.execute_child_workflow
ComposeGreetingWorkflow
ComposeGreetingInput
name),
id="hello-child-workflow-workfl
child-id",

parent_close_policy=ParentClosePolicy
)

Tags: Workflows

Child Workflows Python SDK

Temporal SDKs

https://docs.temporal.io/develop/python/child-workflows Page 5 of 6
Child Workflows - Python SDK | Temporal Platform Documentation 10.04.2025, 17:09

Help us make
Temporal
better.
Contribute to
our
documentation.

https://docs.temporal.io/develop/python/child-workflows Page 6 of 6

You might also like