Skip to main content

Region and environment

Every client takes two top-level kwargs that pick the backend:
KwargValuesDefault
region"ontario", "us" (pending)— (required)
env"production", "staging", "dev", "qa", "demo""staging" if env var STX_ENV is unset
from stx import STX

STX(region="ontario", env="staging")        # api-staging.on.sportsxapp.com
STX(region="ontario", env="production")     # api.on.sportsxapp.com
STX(region="ontario", env="dev")            # api-dev.on.sportsxapp.com
US region hosts are not live yet. Pass region="ontario" for all current environments.

Precedence

env resolves in this order (highest wins):
  1. Keyword argument — STX(env="production")
  2. Environment variable — STX_ENV=production
  3. Profile file — env = production in ~/.stx/credentials
  4. Default — "staging"
Unknown env names raise STXException at construction time.

Custom hosts

For local development against a custom host — a branch-deployed preview, or localhost:
STX(host="http://localhost:4000", email="...", password="...")
Passing host= bypasses the region/env table entirely — the SDK won’t try to look up a hostname. Useful for testing, not recommended in production code.

Environment variables

The SDK reads these at client-construction time:
VariablePurpose
STX_EMAILEmail for login (see Authentication)
STX_PASSWORDPassword for login
STX_ENVDefault env if kwarg is not set
STX_REGIONDefault region if kwarg is not set
STX_PROFILEDefault profile name for ~/.stx/credentials
STX_HOSTOverrides region/env — useful for local dev
STX_SCHEMA_SOURCE"bundled" (default), "latest", or a URL
Empty strings are treated as unset, not as False / "" — so STX_EMAIL= in an unset env file won’t shadow a profile value.

Profile files

~/.stx/credentials uses the same INI format as ~/.aws/credentials:
[default]
region   = ontario
env      = staging
email    = you@example.com
password = your-password

[prod-bot]
region   = ontario
env      = production
email    = bot@example.com
password = bot-password

[local]
host     = http://localhost:4000
email    = dev@example.com
password = dev
Select a profile at client construction:
STX()                            # uses [default]
STX(profile="prod-bot")          # uses [prod-bot]
STX(profile="local")             # uses [local]
Set permissions to 0600 so only your user account can read the file:
chmod 600 ~/.stx/credentials

Schema pinning

The SDK’s field Selections are validated against a GraphQL schema. You control where that schema comes from.
The schema ships with the SDK — byte-for-byte what was on staging at release time. Predictable, testable, no network dependency at client init.
STX(region="ontario", env="production")   # schema_source="bundled" is the default
If the server is running a newer schema, the SDK logs a one-time warning pointing you at pip install --upgrade stx-python. Existing calls keep working — only calls to fields that don’t exist in the bundled schema will raise.

Default field selection

By default every GraphQL call returns all scalar fields — the SDK walks the return type and requests them for you. Override the default for every call on a given client:
from stx import STX, Selection

client = STX(
    region="ontario", env="production",
    default_fields=Selection("marketId", "status"),
)

client.marketInfos()                                    # returns just marketId + status
client.marketInfos(selections=Selection("title"))       # per-call overrides the default
See Presets for canned selections.

Retry policy

All GraphQL calls are wrapped in a RetryPolicy with exponential backoff + decorrelated jitter. Override per-client:
from stx import STX
from stx._retry import RetryPolicy

STX(
    region="ontario", env="production",
    retry=RetryPolicy(max_attempts=5, initial_backoff=0.25, jitter=True),
)
Disable retries entirely:
from stx._retry import RetryPolicy

STX(region="ontario", env="production", retry=RetryPolicy.DISABLED)
See Errors & retries for the full policy.

Logging

The SDK uses the standard logging module under the stx logger:
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger("stx").setLevel(logging.DEBUG)
  • INFO: login, token refresh, WS reconnect events.
  • DEBUG: every GraphQL operation name, WS frame direction, retry attempts.
  • WARNING: schema version skew, backoff exhaustion.
Sensitive values (passwords, full JWTs) are never logged — only redacted previews.

Full-example ~/.stx/credentials

[default]
region   = ontario
env      = staging
email    = dev@example.com
password = dev-password

[prod-readonly]
region   = ontario
env      = production
email    = readonly@example.com
password = readonly-password

[prod-bot]
region   = ontario
env      = production
email    = bot-trader@example.com
password = bot-password
STX()                             # dev staging
STX(profile="prod-readonly")      # prod, read-only account
STX(profile="prod-bot")           # prod, trading account