Environment Configuration
PyTRIO reads process environment variables when it is imported, which suits non-interactive environments such as CI. You can also override the configuration in-process with pytrio.configure(...) before creating a ServiceClient.
Environment Variables
| Environment variable | Equivalent Python configuration | Description |
|---|---|---|
PYTRIO_API_KEY | pytrio.configure(api_key=...) | API key used by the current process; can replace trio login |
PYTRIO_BASE_URL | pytrio.configure(base_url=...) | Trio service root URL; trailing /api and / are normalized |
PYTRIO_ENV | pytrio.configure(env=...) | Local server profile used by the current process |
PYTRIO_LOG_LEVEL | pytrio.configure(log_level=...) | SDK and CLI log level |
For example:
export PYTRIO_ENV=dev
export PYTRIO_API_KEY=trio-key
export PYTRIO_BASE_URL=https://beta.pytrio.com
export PYTRIO_LOG_LEVEL=DEBUG
python train.pyThis is equivalent to the following in-process configuration:
import pytrio
pytrio.configure(
env="dev",
api_key="trio-key",
base_url="https://beta.pytrio.com",
log_level="DEBUG",
)Precedence
Configuration is loaded in the following order, with later values overriding earlier ones:
- SDK defaults.
- The current profile stored on disk.
PYTRIO_*environment variables.- Calls to
pytrio.configure(...). - Explicit arguments at call sites such as
ServiceClient.
PYTRIO_ENV selects and loads its profile before the API key, service URL, and log level override values from that profile. Environment variables affect only the current process and do not modify env.toml or a profile's config.toml. Undefined, empty, or whitespace-only environment variables do not replace existing configuration.
PYTRIO_LOG_LEVEL accepts DEBUG, INFO, WARNING, ERROR, and CRITICAL. Any other value raises configuration.invalid_environment during import.
Client Configuration Snapshots
ServiceClient (and an independently constructed RestClient) copies the current process configuration at creation time. Later calls to pytrio.configure(...) affect only clients created afterward.
import pytrio
pytrio.configure(request_timeout_seconds=10)
first = pytrio.ServiceClient()
pytrio.configure(request_timeout_seconds=30)
second = pytrio.ServiceClient()
# first keeps the 10-second timeout; second uses 30 seconds.Common pytrio.configure(...) Parameters
All arguments are keyword-only; passing None leaves the current setting unchanged.
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | "" | API key for the current process |
base_url | str | "https://pytrio.com" | Trio service root URL (trailing /api and / are normalized) |
env | str | "" (default profile) | Process-local server profile; default / (default) selects the default profile |
home | str | str(Path.home()) | Home directory for .pytrio local files |
log_level | LogLevel | "INFO" | Minimum console log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
request_timeout_seconds | int | 30 | Default request timeout in seconds (>= 1) |
connect_timeout_seconds | float | 60.0 | Maximum time to establish one HTTP connection (> 0) |
retry_window_seconds | float | 1800.0 (30 min) | Maximum continuous retry window on request failures; 0 disables retries |
retry_initial_delay_seconds | float | 1.0 | Initial retry delay in seconds |
retry_multiplier | float | 2.0 | Retry backoff multiplier |
retry_max_delay_seconds | float | 30.0 | Maximum delay between retries in seconds |
training_event_max_in_flight | int | 16 | Maximum concurrent in-flight training requests |
training_event_queue_capacity | int | 64 | Local queue capacity for pending training requests |
sampling_request_max_in_flight | int | 16 | Maximum concurrent in-flight sampling requests |
sampling_request_queue_capacity | int | 64 | Local queue capacity for pending sampling requests |
For error log files and exception handling, see Errors and Diagnostics.