Skip to content

Commit 7a1dd4d

Browse files
authored
Migrate to uv (#170)
1 parent 7577bd6 commit 7a1dd4d

File tree

41 files changed

+3279
-3814
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3279
-3814
lines changed

.github/workflows/ci.yml

+8-9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
runsOn: macos-14
2222
runs-on: ${{ matrix.runsOn || matrix.os }}
2323
steps:
24+
- uses: astral-sh/setup-uv@v5
2425
- name: Print build information
2526
run: "echo head_ref: ${{ github.head_ref }}, ref: ${{ github.ref }}, os: ${{ matrix.os }}, python: ${{ matrix.python }}"
2627
- uses: actions/checkout@v4
@@ -29,10 +30,8 @@ jobs:
2930
- uses: actions/setup-python@v5
3031
with:
3132
python-version: ${{ matrix.python }}
32-
# Using fixed Poetry version until
33-
# https://github.com/python-poetry/poetry/pull/7694 is fixed
34-
- run: python -m pip install --upgrade wheel "poetry==1.4.0" poethepoet
35-
- run: poetry install --with pydantic_converter --with dsl --with encryption --with trio_async
33+
- run: uv tool install poethepoet
34+
- run: uv sync --group=dsl --group=encryption --group=trio-async
3635
- run: poe lint
3736
- run: mkdir junit-xml
3837
- run: poe test -s --junit-xml=junit-xml/${{ matrix.python }}--${{ matrix.os }}.xml
@@ -41,17 +40,17 @@ jobs:
4140
- name: Uninstall pydantic
4241
shell: bash
4342
run: |
44-
echo y | poetry run pip uninstall pydantic
45-
echo y | poetry run pip uninstall pydantic-core
46-
poetry run pip install pydantic==1.10
43+
echo y | uv run pip uninstall pydantic
44+
echo y | uv run pip uninstall pydantic-core
45+
uv run pip install pydantic==1.10
4746
poe test -s --junit-xml=junit-xml/${{ matrix.python }}--${{ matrix.os }}--pydantic-v1.xml tests/pydantic_converter_v1/workflow_test.py
4847
4948
# On latest, run gevent test
5049
- name: Gevent test
5150
if: ${{ matrix.python == '3.12' }}
5251
run: |
53-
poetry install --with gevent
54-
poetry run python gevent_async/test/run_combined.py
52+
uv sync --group gevent
53+
uv run gevent_async/test/run_combined.py
5554
5655
- name: Upload junit-xml artifacts
5756
uses: actions/upload-artifact@v4

README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
# Temporal Python SDK Samples
22

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

55
## Usage
66

77
Prerequisites:
88

9-
* Python >= 3.9
10-
* [Poetry](https://python-poetry.org)
9+
* [uv](https://docs.astral.sh/uv/)
1110
* [Temporal CLI installed](https://docs.temporal.io/cli#install)
1211
* [Local Temporal server running](https://docs.temporal.io/cli/server#start-dev)
1312

13+
The SDK requires Python >= 3.9. You can install Python using uv. For example,
14+
15+
uv python install 3.13
16+
1417
With this repository cloned, run the following at the root of the directory:
1518

16-
poetry install
19+
uv sync
1720

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

20-
poetry run python hello/hello_activity.py
23+
uv run hello/hello_activity.py
2124

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

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

8285
Running the tests requires `poe` to be installed.
8386

84-
python -m pip install poethepoet
87+
uv tool install poethepoet
8588

8689
Once you have `poe` installed you can run:
8790

activity_worker/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ First run the Go workflow worker by running this in the `go_workflow` directory
88

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

11-
poetry run python activity_worker.py
11+
uv run activity_worker.py
1212

1313
The Python code will invoke the Go workflow which will execute the Python activity and return.

bedrock/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ These examples use Amazon's Python SDK (Boto3). To configure Boto3 to use your A
2020

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

23-
poetry install --with bedrock
23+
uv sync --group bedrock
2424

2525
There are 3 Bedrock samples, see the README.md in each sub-directory for instructions on running each.

bedrock/basic/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A basic Bedrock workflow. Starts a workflow with a prompt, generates a response
44

55
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:
66

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

10-
e.g. `poetry run python send_message.py 'What animals are marsupials?'`
10+
e.g. `uv run send_message.py 'What animals are marsupials?'`

bedrock/entity/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ Multi-Turn Chat using an Entity Workflow. The workflow runs forever unless expli
44

55
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:
66

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

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

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

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

18-
Example: `poetry run python get_history.py`
19-
6. To end the chat session, run `poetry run python end_chat.py`
18+
Example: `uv run get_history.py`
19+
6. To end the chat session, run `uv run end_chat.py`

bedrock/signals_and_queries/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ Adding signals & queries to the [basic Bedrock sample](../1_basic). Starts a wor
44

55
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:
66

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

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

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

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

18-
Example: `poetry run python get_history.py`
18+
Example: `uv run get_history.py`
1919
6. The workflow will timeout after inactivity.

cloud_export_to_parquet/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ This is an example workflow to convert exported file from proto to parquet file.
44

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

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

99
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.
1010

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

1313
```bash
14-
poetry run python run_worker.py
14+
uv run run_worker.py
1515
```
1616

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

1919
```bash
20-
poetry run python create_schedule.py
20+
uv run create_schedule.py
2121
```
2222

2323
The workflow should convert exported file in your input s3 bucket to parquet in your specified location.

context_propagation/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ this example, [contextvars](https://docs.python.org/3/library/contextvars.html)
66
To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory to start the
77
worker:
88

9-
poetry run python worker.py
9+
uv run worker.py
1010

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

13-
poetry run python starter.py
13+
uv run starter.py
1414

1515
The starter terminal should complete with the hello result and the worker terminal should show the logs with the
1616
propagated user ID contextual information flowing through the workflows/activities.

custom_converter/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ This sample shows how to make a custom payload converter for a type not natively
55
To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory to start the
66
worker:
77

8-
poetry run python worker.py
8+
uv run worker.py
99

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

12-
poetry run python starter.py
12+
uv run starter.py
1313

1414
The workflow should complete with the hello result. If the custom converter was not set for the custom input and output
1515
classes, we would get an error on the client side and on the worker side.

custom_decorator/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ decorator that automatically configures an activity to heartbeat twice as freque
66
To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory to start the
77
worker:
88

9-
poetry run python worker.py
9+
uv run worker.py
1010

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

13-
poetry run python starter.py
13+
uv run starter.py
1414

1515
The workflow will be started, and then after 5 seconds will be sent a signal to cancel its forever-running activity.
1616
The activity has a heartbeat timeout set to 2s, so since it has the `@auto_heartbeater` decorator set, it will heartbeat

dsl/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ samples [in TypeScript](https://github.com/temporalio/samples-typescript/tree/ma
66

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

9-
poetry install --with dsl
9+
uv sync --group dsl
1010

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

14-
poetry run python worker.py
14+
uv run worker.py
1515

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

19-
poetry run python starter.py workflow1.yaml
19+
uv run starter.py workflow1.yaml
2020

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

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

26-
poetry run python starter.py workflow2.yaml
26+
uv run starter.py workflow2.yaml
2727

2828
This sample gives a guide of how one can write a workflow to interpret arbitrary steps from a user-provided DSL. Many
2929
DSL models are more advanced and are more specific to conform to business logic needs.

encryption/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ samples [in TypeScript](https://github.com/temporalio/samples-typescript/tree/ma
77

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

10-
poetry install --with encryption
10+
uv sync --group encryption
1111

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

15-
poetry run python worker.py
15+
uv run worker.py
1616

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

19-
poetry run python starter.py
19+
uv run starter.py
2020

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

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

34-
poetry run python codec_server.py
34+
uv run codec_server.py
3535

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

gevent_async/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ workflows.
1212

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

15-
poetry install --with gevent
15+
uv sync --group gevent
1616

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

20-
poetry run python worker.py
20+
uv run worker.py
2121

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

25-
poetry run python starter.py
25+
uv run starter.py
2626

2727
The workflow should run and complete with the hello result. Note on the worker terminal there will be logs of the
2828
workflow and activity executions.

hello/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ These samples show basic workflow and activity features.
55
To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory to run the
66
`hello_activity.py` sample:
77

8-
poetry run python hello_activity.py
8+
uv run hello_activity.py
99

1010
The result will be:
1111

langchain/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This sample shows you how you can use Temporal to orchestrate workflows for [Lan
44

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

7-
poetry install --with langchain
7+
uv sync --group langchain
88

99
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.
1010

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

16-
poetry run python worker.py
16+
uv run worker.py
1717

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

20-
poetry run python starter.py
20+
uv run starter.py
2121

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

langchain/activities.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ async def translate_phrase(params: TranslateParams) -> dict:
2626
)
2727
chain = chat_prompt | ChatOpenAI()
2828
# Use the asynchronous invoke method
29-
return await chain.ainvoke({"phrase": params.phrase, "language": params.language})
29+
return dict(
30+
await chain.ainvoke({"phrase": params.phrase, "language": params.language})
31+
)

message_passing/introduction/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Then create two terminals and `cd` to this directory.
1010

1111
Run the worker in one terminal:
1212

13-
poetry run python worker.py
13+
uv run worker.py
1414

1515
And execute the workflow in the other terminal:
1616

17-
poetry run python starter.py
17+
uv run starter.py
1818

message_passing/safe_message_handlers/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ To run, first see [README.md](../../README.md) for prerequisites.
1212

1313
Then, run the following from this directory to run the worker:
1414
\
15-
poetry run python worker.py
15+
uv run worker.py
1616

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

19-
poetry run python starter.py
19+
uv run starter.py
2020

2121
This will start a worker to run your workflow and activities, then start a ClusterManagerWorkflow and put it through its paces.

message_passing/update_with_start/lazy_initialization/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ To run, first see the main [README.md](../../../README.md) for prerequisites.
88

99
Then run the following from this directory:
1010

11-
poetry run python worker.py
11+
uv run worker.py
1212

1313
Then, in another terminal:
1414

15-
poetry run python starter.py
15+
uv run starter.py
1616

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

0 commit comments

Comments
 (0)