Skip to content

API

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:

bash
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.py

This is equivalent to the following in-process configuration:

python
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:

  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 ​

ServiceClient (and an independently constructed RestClient) copies the current process configuration at creation time. Later calls to pytrio.configure(...) affect only clients created afterward.

python
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.

ParameterTypeDefaultDescription
api_keystr""API key for the current process
base_urlstr"https://pytrio.com"Trio service root URL (trailing /api and / are normalized)
envstr"" (default profile)Process-local server profile; default / (default) selects the default profile
homestrstr(Path.home())Home directory for .pytrio local files
log_levelLogLevel"INFO"Minimum console log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
request_timeout_secondsint30Default request timeout in seconds (>= 1)
connect_timeout_secondsfloat60.0Maximum time to establish one HTTP connection (> 0)
retry_window_secondsfloat1800.0 (30 min)Maximum continuous retry window on request failures; 0 disables retries
retry_initial_delay_secondsfloat1.0Initial retry delay in seconds
retry_multiplierfloat2.0Retry backoff multiplier
retry_max_delay_secondsfloat30.0Maximum delay between retries in seconds
training_event_max_in_flightint16Maximum concurrent in-flight training requests
training_event_queue_capacityint64Local queue capacity for pending training requests
sampling_request_max_in_flightint16Maximum concurrent in-flight sampling requests
sampling_request_queue_capacityint64Local queue capacity for pending sampling requests

For error log files and exception handling, see Errors and Diagnostics.