Python
Read flags from Python, including the config shape that is easy to get wrong.
A Python client resolving flags, with missing keys caught at start-up.
- An API key from API Keys
Flags in Python, on the server.
pip install variably-sdk
The client takes one argument
A config dict, or a VariablyConfig. Not keyword arguments — VariablyClient(api_key=...) raises
TypeError.
import os
from variably import VariablyClient
client = VariablyClient({
"api_key": os.environ["VARIABLY_API_KEY"],
"base_url": os.environ["VARIABLY_BASE_URL"],
})
base_url is required and has no default, so evaluation data cannot be sent to an unintended host.
timeout (milliseconds, default 5000), retry_attempts, cache and log_level are also accepted.
Reading flags
The context is user_id, not key — that spelling differs from the JavaScript SDKs.
user = {"user_id": "user-123", "country": "JP"}
enabled = client.evaluate_flag_bool("checkoutRedesign", False, user)
layout = client.evaluate_flag_string("checkoutLayout", "control", user)
count = client.evaluate_flag_number("maxItems", 10, user)
config = client.evaluate_flag_json("checkoutConfig", {}, user)
flags = client.all_flags(user)
Note the argument order: flag key, default, context.
Catch missing flags at start-up
missing = client.validate_flags(["checkoutRedesign", "newPricing"], user)
if missing:
raise RuntimeError(f"Flags not defined in Variably: {', '.join(missing)}")
A flag the project does not define is an error rather than a value. A typo or an unseeded environment would otherwise look exactly like a flag that is switched off, and the application would run on defaults appearing healthy.
The same package does LLM evaluation
variably-sdk also carries observe() for scoring LLM output. If you arrived here from
Setup you already have it installed — the flag client above is the same package.