Advanced

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 variableEquivalent Python configurationDescription
PYTRIO_API_KEYpytrio.configure(api_key=...)API key used by the current process; can replace trio login
PYTRIO_BASE_URLpytrio.configure(base_url=...)Trio service root URL; trailing /api and / are normalized
PYTRIO_ENVpytrio.configure(env=...)Local server profile used by the current process
PYTRIO_LOG_LEVELpytrio.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.cn
export PYTRIO_LOG_LEVEL=DEBUG
python train.py

This is equivalent to the following in-process configuration:

import pytrio

pytrio.configure(
    env="dev",
    api_key="trio-key",
    base_url="https://beta.pytrio.cn",
    log_level="DEBUG",
)

Precedence

Configuration is loaded in the following order, with later values overriding earlier ones:

  1. SDK defaults.
  2. The current profile stored on disk.
  3. PYTRIO_* environment variables.
  4. Calls to pytrio.configure(...).
  5. 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

A root ServiceClient copies the current process configuration when construction begins. Its Control, Actor, Telemetry, downloader, executor, and derived clients all use that runtime snapshot. Later calls to pytrio.configure(...) affect only root clients created afterward.

import pytrio

pytrio.configure(timeout=10)
first = pytrio.ServiceClient()

pytrio.configure(timeout=30)
second = pytrio.ServiceClient()

# first keeps the 10-second timeout; second uses 30 seconds.
Was this documentation helpful?

On this page