Skip to main content

Python SDK for the qbrix multi-armed bandit platform

Project description

Qbrix

Python SDK for the qbrix platform.

License Coverage Python 3.10+ Pydantic v2 httpx


Typed sync and async clients for Qbrix — pool/experiment/gate management and the agent select/feedback loop.

Installation

pip install qbrix

Quick Start

Set your credentials as environment variables and call resources directly — no client instantiation needed:

export QBRIX_API_KEY="optiq_xxx"
export QBRIX_BASE_URL="https://api.qbrix.io"
import qbrix

# 1. Create a pool of arms (variants)
pool = qbrix.pool.create(
    name="homepage-buttons",
    arms=[{"name": "blue"}, {"name": "green"}, {"name": "red"}],
)

# 2. Create an experiment with a bandit policy
exp = qbrix.experiment.create(
    name="button-color-test",
    pool_id=pool.id,
    policy="BetaTSPolicy",
)

# 3. Select an arm for a user
result = qbrix.agent.select(
    experiment_id=exp.id,
    context={"id": "user-123", "metadata": {"country": "US"}},
)
print(result.arm.name)       # "green"
print(result.is_default)     # False (bandit selected)

# 4. Send feedback (reward) after observing the outcome
qbrix.agent.feedback(request_id=result.request_id, reward=1.0)

The system learns from every reward and adjusts future selections automatically.

Explicit Client

For full control over configuration or lifecycle (e.g. closing the HTTP connection, using a context manager), instantiate the client directly:

from qbrix import Qbrix

with Qbrix(api_key="optiq_xxx", base_url="https://api.qbrix.io") as client:
    pool = client.pool.create(
        name="homepage-buttons",
        arms=[{"name": "blue"}, {"name": "green"}, {"name": "red"}],
    )
    result = client.agent.select(experiment_id="exp-uuid", context={"id": "user-123"})
    client.agent.feedback(request_id=result.request_id, reward=1.0)

Async

from qbrix import AsyncQbrix

async with AsyncQbrix(api_key="optiq_xxx") as client:
    result = await client.agent.select(
        experiment_id="exp-uuid",
        context={"id": "user-456"},
    )
    await client.agent.feedback(request_id=result.request_id, reward=1.0)

Configuration

Constructor kwargs take priority over environment variables, which take priority over defaults.

export QBRIX_API_KEY="optiq_xxx"
export QBRIX_BASE_URL="https://api.qbrix.io"
from qbrix import Qbrix

client = Qbrix()  # picks up env vars automatically
Env Var Default Description
QBRIX_API_KEY None API key (optiq_xxx)
QBRIX_BASE_URL http://localhost:8080 Proxy service URL
QBRIX_TIMEOUT 30.0 Request timeout (seconds)
QBRIX_MAX_RETRIES 3 Retry count on 429/5xx

Feature Gates

Attach a feature gate to control rollout before the bandit kicks in:

import qbrix

qbrix.gate.create(
    experiment_id=exp.id,
    enabled=True,
    rollout_percentage=80.0,
    default_arm_id=pool.arms[0].id,
    rules=[
        {"key": "plan", "operator": "==", "value": "enterprise", "arm_id": pool.arms[1].id},
    ],
)

# Gate-matched selections return is_default=True
result = qbrix.agent.select(
    experiment_id=exp.id,
    context={"id": "user-789", "metadata": {"plan": "enterprise"}},
)
print(result.is_default)  # True

Error Handling

import qbrix
from qbrix import NotFoundError, RateLimitedError

try:
    exp = qbrix.experiment.get("nonexistent-id")
except NotFoundError as e:
    print(f"Not found: {e.detail}")
except RateLimitedError as e:
    print(f"Retry after {e.retry_after}s")

Supported Policies

Policy Type Best For
BetaTSPolicy Stochastic Binary rewards (clicks, conversions)
GaussianTSPolicy Stochastic Continuous rewards
UCB1TunedPolicy Stochastic Theoretical regret guarantees
KLUCBPolicy Stochastic Binary rewards with tight bounds
MOSSPolicy Stochastic Fixed horizon problems
LinUCBPolicy Contextual Linear reward models with features
LinTSPolicy Contextual Linear models with uncertainty
EXP3Policy Adversarial Non-stationary environments
FPLPolicy Adversarial Follow the perturbed leader

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qbrix-0.1.4.tar.gz (117.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qbrix-0.1.4-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file qbrix-0.1.4.tar.gz.

File metadata

  • Download URL: qbrix-0.1.4.tar.gz
  • Upload date:
  • Size: 117.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for qbrix-0.1.4.tar.gz
Algorithm Hash digest
SHA256 a281d72e1e19f51b2df3035573cdcc253e90f52184ddd4f81cd209bca71130c9
MD5 68e90c2406757c7d2624ef5c8abf1b55
BLAKE2b-256 e8bb3d42a9079676ead19874c9145cacc4ea02fdfe01dad28602957f7344e6b4

See more details on using hashes here.

File details

Details for the file qbrix-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: qbrix-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for qbrix-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4d7e473ca624a65e2dabb2aba1d0670ad95ba08088bc0f80364bccd402ac5fae
MD5 6358e964ce4068d3f35ae0f77f866d0a
BLAKE2b-256 7d1b81582e242de4b25bfdff716e2ba92a97d45837a2dc174a973d0cac52d562

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page