Skip to content

Commit a9d0eb1

Browse files
committed
update sample
1 parent c207986 commit a9d0eb1

3 files changed

Lines changed: 15 additions & 22 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Some examples require extra dependencies. See each sample's directory for specif
6666
* [custom_metric](custom_metric) - Custom metric to record the workflow type in the activity schedule to start latency.
6767
* [dsl](dsl) - DSL workflow that executes steps defined in a YAML file.
6868
* [encryption](encryption) - Apply end-to-end encryption for all input/output.
69+
* [env_config](env_config) - Load client configuration from TOML files with programmatic overrides.
6970
* [gevent_async](gevent_async) - Combine gevent and Temporal.
7071
* [langchain](langchain) - Orchestrate workflows for LangChain.
7172
* [message_passing/introduction](message_passing/introduction/) - Introduction to queries, signals, and updates.

env_config/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Temporal External Client Configuration Samples
22

3-
This directory contains Python samples that demonstrate how to use the Temporal SDK's external client configuration feature. This feature allows you to configure a `temporalio.client.Client` using a TOML file and/or environment variables, decoupling connection settings from your application code.
3+
This directory contains Python samples that demonstrate how to use the Temporal SDK's external client configuration feature. This feature allows you to configure a `temporalio.client.Client` using a TOML file and/or programmatic overrides, decoupling connection settings from your application code.
44

55
## Prerequisites
66

@@ -30,7 +30,7 @@ python3 env_config/load_default.py
3030

3131
### `load_profile.py`
3232

33-
This sample demonstrates loading the `staging` profile by name (which has an incorrect address) and then correcting the address using an environment variable. This highlights how environment variables can be used to fix or override file-based configuration.
33+
This sample demonstrates loading the `staging` profile by name (which has an incorrect address) and then correcting the address programmatically. This highlights the recommended approach for overriding configuration values at runtime.
3434

3535
**To run this sample:**
3636

env_config/load_profile.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
This sample demonstrates loading a named environment configuration profile and
3-
overriding its values with environment variables.
3+
programmatically overriding its values.
44
"""
55

66
import asyncio
@@ -12,37 +12,29 @@
1212

1313
async def main():
1414
"""
15-
Demonstrates loading a named profile and overriding it with env vars.
15+
Demonstrates loading a named profile and overriding values programmatically.
1616
"""
17-
print("--- Loading 'staging' profile with environment variable overrides ---")
17+
print("--- Loading 'staging' profile with programmatic overrides ---")
1818

1919
config_file = Path(__file__).parent / "config.toml"
2020
profile_name = "staging"
2121

22-
# In a real application, these would be set in your shell or deployment
23-
# environment (e.g., `export TEMPORAL_ADDRESS=localhost:7233`).
24-
# For this sample, we pass them as a dictionary to demonstrate.
25-
override_env = {
26-
"TEMPORAL_ADDRESS": "localhost:7233",
27-
}
28-
print("The 'staging' profile in config.toml has an incorrect address.")
29-
print("Using mock environment variables to override and correct it:")
30-
for key, value in override_env.items():
31-
print(f" {key}={value}")
32-
33-
# Load the 'staging' profile and apply environment variable overrides.
22+
print("The 'staging' profile in config.toml has an incorrect address (localhost:9999).")
23+
print("We'll programmatically override it to the correct address.")
24+
25+
# Load the 'staging' profile.
3426
connect_config = ClientConfig.load_client_connect_config(
3527
profile=profile_name,
3628
config_file=str(config_file),
37-
override_env_vars=override_env,
3829
)
3930

31+
# Override the target host to the correct address.
32+
# This is the recommended way to override configuration values.
33+
connect_config["target_host"] = "localhost:7233"
34+
4035
print(f"\nLoaded '{profile_name}' profile from {config_file} with overrides.")
41-
print(f" Address: {connect_config.get('target_host')}")
36+
print(f" Address: {connect_config.get('target_host')} (overridden from localhost:9999)")
4237
print(f" Namespace: {connect_config.get('namespace')}")
43-
print(
44-
"\nNote how the incorrect address from the file was corrected by the env var."
45-
)
4638

4739
print("\nAttempting to connect to client...")
4840
try:

0 commit comments

Comments
 (0)