Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to uv #170

Merged
merged 22 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
runsOn: macos-14
runs-on: ${{ matrix.runsOn || matrix.os }}
steps:
- uses: astral-sh/setup-uv@v5
- name: Print build information
run: "echo head_ref: ${{ github.head_ref }}, ref: ${{ github.ref }}, os: ${{ matrix.os }}, python: ${{ matrix.python }}"
- uses: actions/checkout@v4
Expand All @@ -29,10 +30,8 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
# Using fixed Poetry version until
# https://github.com/python-poetry/poetry/pull/7694 is fixed
- run: python -m pip install --upgrade wheel "poetry==1.4.0" poethepoet
- run: poetry install --with pydantic_converter --with dsl --with encryption --with trio_async
- run: uv tool install poethepoet
- run: uv sync --group=dsl --group=encryption --group=trio-async
- run: poe lint
- run: mkdir junit-xml
- run: poe test -s --junit-xml=junit-xml/${{ matrix.python }}--${{ matrix.os }}.xml
Expand All @@ -41,17 +40,17 @@ jobs:
- name: Uninstall pydantic
shell: bash
run: |
echo y | poetry run pip uninstall pydantic
echo y | poetry run pip uninstall pydantic-core
poetry run pip install pydantic==1.10
echo y | uv run pip uninstall pydantic
echo y | uv run pip uninstall pydantic-core
uv run pip install pydantic==1.10
poe test -s --junit-xml=junit-xml/${{ matrix.python }}--${{ matrix.os }}--pydantic-v1.xml tests/pydantic_converter_v1/workflow_test.py

# On latest, run gevent test
- name: Gevent test
if: ${{ matrix.python == '3.12' }}
run: |
poetry install --with gevent
poetry run python gevent_async/test/run_combined.py
uv sync --group gevent
uv run gevent_async/test/run_combined.py

- name: Upload junit-xml artifacts
uses: actions/upload-artifact@v4
Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# Temporal Python SDK Samples

This is the set of Python samples for the [Python SDK](https://github.com/temporalio/sdk-python).
This is a collection of samples showing how to use the [Python SDK](https://github.com/temporalio/sdk-python).

## Usage

Prerequisites:

* Python >= 3.9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave the Python version constraints?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want users thinking they have to install a special Python version. uv users should install python using

uv python install 3.9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to clarify somewhere that they should run that command.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want users thinking they have to install a special Python version. uv users should install python using

Right, "Python >= 3.9" just means "the software in this repository needs at least Python 3.9", it doesn't say how to install it or that it has to be any specific version. Our SDK and samples repo READMEs need to clarify which versions of Python they work with.

Copy link
Contributor Author

@dandavison dandavison Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this? c99cefe

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

* [Poetry](https://python-poetry.org)
* [uv](https://docs.astral.sh/uv/)
* [Temporal CLI installed](https://docs.temporal.io/cli#install)
* [Local Temporal server running](https://docs.temporal.io/cli/server#start-dev)

The SDK requires Python >= 3.9. 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:

poetry install
uv sync

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

poetry run python hello/hello_activity.py
uv run hello/hello_activity.py

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

Expand Down Expand Up @@ -81,7 +84,7 @@ Some examples require extra dependencies. See each sample's directory for specif

Running the tests requires `poe` to be installed.

python -m pip install poethepoet
uv tool install poethepoet

Once you have `poe` installed you can run:

Expand Down
2 changes: 1 addition & 1 deletion activity_worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ First run the Go workflow worker by running this in the `go_workflow` directory

Then in another terminal, run the sample from this directory:

poetry run python activity_worker.py
uv run activity_worker.py

The Python code will invoke the Go workflow which will execute the Python activity and return.
2 changes: 1 addition & 1 deletion bedrock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ These examples use Amazon's Python SDK (Boto3). To configure Boto3 to use your A

For these sample, the optional `bedrock` dependency group must be included. To include, run:

poetry install --with bedrock
uv sync --group bedrock

There are 3 Bedrock samples, see the README.md in each sub-directory for instructions on running each.
4 changes: 2 additions & 2 deletions bedrock/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A basic Bedrock workflow. Starts a workflow with a prompt, generates a response

To run, first see `samples-python` [README.md](../../README.md), and `bedrock` [README.md](../README.md) for prerequisites specific to this sample. Once set up, run the following from this directory:

1. Run the worker: `poetry run python run_worker.py`
1. Run the worker: `uv run run_worker.py`
2. In another terminal run the client with a prompt:

e.g. `poetry run python send_message.py 'What animals are marsupials?'`
e.g. `uv run send_message.py 'What animals are marsupials?'`
10 changes: 5 additions & 5 deletions bedrock/entity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ Multi-Turn Chat using an Entity Workflow. The workflow runs forever unless expli

To run, first see `samples-python` [README.md](../../README.md), and `bedrock` [README.md](../README.md) for prerequisites specific to this sample. Once set up, run the following from this directory:

1. Run the worker: `poetry run python run_worker.py`
1. Run the worker: `uv run run_worker.py`
2. In another terminal run the client with a prompt.

Example: `poetry run python send_message.py 'What animals are marsupials?'`
Example: `uv run send_message.py 'What animals are marsupials?'`

3. View the worker's output for the response.
4. Give followup prompts by signaling the workflow.

Example: `poetry run python send_message.py 'Do they lay eggs?'`
Example: `uv run send_message.py 'Do they lay eggs?'`
5. Get the conversation history summary by querying the workflow.

Example: `poetry run python get_history.py`
6. To end the chat session, run `poetry run python end_chat.py`
Example: `uv run get_history.py`
6. To end the chat session, run `uv run end_chat.py`
8 changes: 4 additions & 4 deletions bedrock/signals_and_queries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ Adding signals & queries to the [basic Bedrock sample](../1_basic). Starts a wor

To run, first see `samples-python` [README.md](../../README.md), and `bedrock` [README.md](../README.md) for prerequisites specific to this sample. Once set up, run the following from this directory:

1. Run the worker: `poetry run python run_worker.py`
1. Run the worker: `uv run run_worker.py`
2. In another terminal run the client with a prompt.

Example: `poetry run python send_message.py 'What animals are marsupials?'`
Example: `uv run send_message.py 'What animals are marsupials?'`

3. View the worker's output for the response.
4. Give followup prompts by signaling the workflow.

Example: `poetry run python send_message.py 'Do they lay eggs?'`
Example: `uv run send_message.py 'Do they lay eggs?'`
5. Get the conversation history by querying the workflow.

Example: `poetry run python get_history.py`
Example: `uv run get_history.py`
6. The workflow will timeout after inactivity.
6 changes: 3 additions & 3 deletions cloud_export_to_parquet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ This is an example workflow to convert exported file from proto to parquet file.

Please make sure your python is 3.9 above. For this sample, run:

poetry install --with cloud_export_to_parquet
uv sync --group=cloud-export-to-parquet

Before you start, please modify workflow input in `create_schedule.py` with your s3 bucket and namespace. Also make sure you've the right AWS permission set up in your environment to allow this workflow read and write to your s3 bucket.

To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory to start the worker:

```bash
poetry run python run_worker.py
uv run run_worker.py
```

This will start the worker. Then, in another terminal, run the following to execute the schedule:

```bash
poetry run python create_schedule.py
uv run create_schedule.py
```

The workflow should convert exported file in your input s3 bucket to parquet in your specified location.
4 changes: 2 additions & 2 deletions context_propagation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ this example, [contextvars](https://docs.python.org/3/library/contextvars.html)
To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory to start the
worker:

poetry run python worker.py
uv run worker.py

This will start the worker. Then, in another terminal, run the following to execute the workflow:

poetry run python starter.py
uv run starter.py

The starter terminal should complete with the hello result and the worker terminal should show the logs with the
propagated user ID contextual information flowing through the workflows/activities.
4 changes: 2 additions & 2 deletions custom_converter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ This sample shows how to make a custom payload converter for a type not natively
To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory to start the
worker:

poetry run python worker.py
uv run worker.py

This will start the worker. Then, in another terminal, run the following to execute the workflow:

poetry run python starter.py
uv run starter.py

The workflow should complete with the hello result. If the custom converter was not set for the custom input and output
classes, we would get an error on the client side and on the worker side.
4 changes: 2 additions & 2 deletions custom_decorator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ decorator that automatically configures an activity to heartbeat twice as freque
To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory to start the
worker:

poetry run python worker.py
uv run worker.py

This will start the worker. Then, in another terminal, run the following to execute the workflow:

poetry run python starter.py
uv run starter.py

The workflow will be started, and then after 5 seconds will be sent a signal to cancel its forever-running activity.
The activity has a heartbeat timeout set to 2s, so since it has the `@auto_heartbeater` decorator set, it will heartbeat
Expand Down
8 changes: 4 additions & 4 deletions dsl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ samples [in TypeScript](https://github.com/temporalio/samples-typescript/tree/ma

For this sample, the optional `dsl` dependency group must be included. To include, run:

poetry install --with dsl
uv sync --group dsl

To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory to start the
worker:

poetry run python worker.py
uv run worker.py

This will start the worker. Then, in another terminal, run the following to execute a workflow of steps defined in
[workflow1.yaml](workflow1.yaml):

poetry run python starter.py workflow1.yaml
uv run starter.py workflow1.yaml

This will run the workflow and show the final variables that the workflow returns. Looking in the worker terminal, each
step executed will be visible.

Similarly we can do the same for the more advanced [workflow2.yaml](workflow2.yaml) file:

poetry run python starter.py workflow2.yaml
uv run starter.py workflow2.yaml

This sample gives a guide of how one can write a workflow to interpret arbitrary steps from a user-provided DSL. Many
DSL models are more advanced and are more specific to conform to business logic needs.
8 changes: 4 additions & 4 deletions encryption/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ samples [in TypeScript](https://github.com/temporalio/samples-typescript/tree/ma

For this sample, the optional `encryption` dependency group must be included. To include, run:

poetry install --with encryption
uv sync --group encryption

To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory to start the
worker:

poetry run python worker.py
uv run worker.py

This will start the worker. Then, in another terminal, run the following to execute the workflow:

poetry run python starter.py
uv run starter.py

The workflow should complete with the hello result. To view the workflow, use [temporal](https://docs.temporal.io/cli):

Expand All @@ -31,7 +31,7 @@ Note how the result looks like (with wrapping removed):
This is because the data is encrypted and not visible. To make data visible to external Temporal tools like `temporal` and
the UI, start a codec server in another terminal:

poetry run python codec_server.py
uv run codec_server.py

Now with that running, run `temporal` again with the codec endpoint:

Expand Down
6 changes: 3 additions & 3 deletions gevent_async/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ workflows.

For this sample, the optional `gevent` dependency group must be included. To include, run:

poetry install --with gevent
uv sync --group gevent

To run the sample, first see [README.md](../README.md) for prerequisites such as having a localhost Temporal server
running. Then, run the following from this directory to start the worker:

poetry run python worker.py
uv run worker.py

This will start the worker. The worker has a workflow and two activities, one `asyncio` based and one gevent based. Now
in another terminal, run the following from this directory to execute the workflow:

poetry run python starter.py
uv run starter.py

The workflow should run and complete with the hello result. Note on the worker terminal there will be logs of the
workflow and activity executions.
2 changes: 1 addition & 1 deletion hello/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ These samples show basic workflow and activity features.
To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory to run the
`hello_activity.py` sample:

poetry run python hello_activity.py
uv run hello_activity.py

The result will be:

Expand Down
6 changes: 3 additions & 3 deletions langchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This sample shows you how you can use Temporal to orchestrate workflows for [Lan

For this sample, the optional `langchain` dependency group must be included. To include, run:

poetry install --with langchain
uv sync --group langchain

Export your [OpenAI API key](https://platform.openai.com/api-keys) as an environment variable. Replace `YOUR_API_KEY` with your actual OpenAI API key.

Expand All @@ -13,11 +13,11 @@ Export your [OpenAI API key](https://platform.openai.com/api-keys) as an environ
To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory to start the
worker:

poetry run python worker.py
uv run worker.py

This will start the worker. Then, in another terminal, run the following to execute a workflow:

poetry run python starter.py
uv run starter.py

Then, in another terminal, run the following command to translate a phrase:

Expand Down
4 changes: 3 additions & 1 deletion langchain/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ async def translate_phrase(params: TranslateParams) -> dict:
)
chain = chat_prompt | ChatOpenAI()
# Use the asynchronous invoke method
return await chain.ainvoke({"phrase": params.phrase, "language": params.language})
return dict(
await chain.ainvoke({"phrase": params.phrase, "language": params.language})
)
4 changes: 2 additions & 2 deletions message_passing/introduction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Then create two terminals and `cd` to this directory.

Run the worker in one terminal:

poetry run python worker.py
uv run worker.py

And execute the workflow in the other terminal:

poetry run python starter.py
uv run starter.py

4 changes: 2 additions & 2 deletions message_passing/safe_message_handlers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ To run, first see [README.md](../../README.md) for prerequisites.

Then, run the following from this directory to run the worker:
\
poetry run python worker.py
uv run worker.py

Then, in another terminal, run the following to execute the workflow:

poetry run python starter.py
uv run starter.py

This will start a worker to run your workflow and activities, then start a ClusterManagerWorkflow and put it through its paces.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ To run, first see the main [README.md](../../../README.md) for prerequisites.

Then run the following from this directory:

poetry run python worker.py
uv run worker.py

Then, in another terminal:

poetry run python starter.py
uv run starter.py

This will start a worker to run your workflow and activities, then simulate a backend application receiving
requests to add items to a shopping cart, before finalizing the order.
Loading
Loading