samples-python
samples-python copied to clipboard
Add Request/Response sample with activity-based responses (fixes #6)
What was changed
- Added a new sample directory
reqrespactivityto the repository. - Ported the Request/Response demo from Go to Python, which demonstrates how to send a request (via a signal) to a workflow and receive a response via a callback activity.
- This sample includes:
-
workflow.py: Contains the workflow definition, data models, and the uppercase activity. -
requester.py: Implements a requester that signals the workflow and awaits the callback response. -
starter.py: Starts the workflow. -
worker.py: Runs the workflow and activity worker. -
requester_run.py: Continuously sends requests (e.g., "foo0", "foo1", etc.) to the workflow and prints the uppercase responses.
-
- An updated README (
README.md) provides detailed instructions on running the sample.
Why?
- To provide a Python port of the Request/Response demo as seen in the Go samples.
- This sample demonstrates the use of Temporal's Python SDK for activity-based responses where the workflow processes signal-based requests and responds using a callback activity.
- The implementation serves as a reference for users looking to integrate similar functionality in their Python applications.
Checklist
- Closes #6 and #7
- How was this tested:
- A Temporal server was run locally using Docker.
- The worker was started via
python worker.pyto register the workflow and activity. - The workflow was started using
python starter.pyand confirmed to be running. - The requester was executed using
python requester_run.py, which sent requests (e.g., "foo0", "foo1", etc.) and received correct uppercase responses ("FOO0", "FOO1", etc.).
- Any docs updates needed?
- The new sample includes its own README that documents the sample and mirrors the instructions from the Go version.
- No further updates to docs.temporal.io are required at this time.
https://github.com/temporalio/samples-python/issues/6 and the Go samples predate Workflow Update. We now recommend using workflow update for request/response instead of the "response activity" pattern.