Skip to main content

Official Python SDK for the smplkit platform

Project description

smplkit Python SDK

PyPI Version Build Coverage License Docs

The official Python SDK for smplkit — simple application infrastructure that just works.

Installation

pip install smplkit-sdk

Requirements

  • Python 3.10+

Quick Start

The SDK ships two top-level clients, each with a clearly-scoped purpose:

Client Use case Construction side effects
SmplClient / AsyncSmplClient Runtime instrumentation — flag evaluation, config reads, log emission Auto-registers a service context, starts a metrics thread, opens a websocket
SmplManagementClient / AsyncSmplManagementClient Management / CRUD — setup scripts, CI/CD, admin tooling None — pure HTTP setup

Runtime: SmplClient

from smplkit import Context, SmplClient

with SmplClient(api_key="sk_api_...", environment="production", service="my-svc") as client:
    # Resolve config values for the current environment
    db = client.config.get("database")  # {"host": "...", "port": 5432}

    # Set the current request's context once (typically from middleware) —
    # contextvars provides per-request / per-thread isolation automatically.
    client.set_context([
        Context("user", request.user.id, plan=request.user.plan),
        Context("account", request.account.id, region=request.account.region),
    ])

    # Evaluate a flag — picks up the context set above.
    checkout_v2 = client.flags.boolean_flag("checkout-v2", default=False)
    if checkout_v2.get():
        ...

    # Opt in to runtime logging level control
    client.logging.start()

    # Need to reach the management API from a runtime context?
    # Every SmplClient owns an internal management client at `client.manage`.
    cfg = client.manage.config.get("database")

set_context() returns a scope object that doubles as a with block, so you can override context for a single block (e.g. impersonation):

with client.set_context([Context("user", "u-impersonated", plan="enterprise")]):
    if checkout_v2.get():
        ...
# original context restored here

For deterministic startup — pre-fetch all flags + configs and wait for the live-updates websocket before serving traffic — call client.wait_until_ready() once at boot.

Management: SmplManagementClient

from smplkit import SmplManagementClient

with SmplManagementClient(api_key="sk_api_...") as mgmt:
    # Configs
    cfg = mgmt.config.new("my_service", name="My Service")
    cfg.save()
    configs = mgmt.config.list()

    # Flags
    flag = mgmt.flags.new_boolean_flag("checkout-v2", default=False)
    flag.save()
    flags = mgmt.flags.list()

    # Loggers + log groups
    logger = mgmt.loggers.new("sql", name="SQL Logger")
    logger.save()
    grp = mgmt.log_groups.new("databases", name="Databases")
    grp.save()

    # App-service-owned resources
    for env in mgmt.environments.list():
        print(env.id)
    mgmt.contexts.register([...])
    settings = mgmt.account_settings.get()

The management client takes only api_key (plus optional profile, base_domain, scheme, debug) — environment and service have no meaning for CRUD work and are deliberately rejected.

For async usage, swap SmplClientAsyncSmplClient and SmplManagementClientAsyncSmplManagementClient; method bodies become await-able:

from smplkit import AsyncSmplClient, AsyncSmplManagementClient

async with AsyncSmplClient(api_key="sk_api_...", environment="prod", service="svc") as client:
    db = await client.config.get("database")

async with AsyncSmplManagementClient(api_key="sk_api_...") as mgmt:
    cfg = await mgmt.config.get("my_service")
    configs = await mgmt.config.list()

Which client should I use?

  • Inside a request handler / running serviceSmplClient. You want lazy-fetched runtime state, the context registration loop, metrics, and the live-update websocket.
  • In a setup script / CI job / admin CLI / seederSmplManagementClient. No runtime side effects, no auto-registered service rows leaking into target accounts, no websocket dangling open.

The two clients can be used together in the same process — e.g. a runtime app that occasionally needs to reach into the management API for an admin endpoint. To save you from juggling two clients, every SmplClient exposes a built-in management client at client.manage (sharing HTTP transports under the hood); reach for SmplManagementClient directly only for setup scripts, CI jobs, and admin tooling that have no runtime side effects to begin with.

Management namespaces

SmplManagementClient (and client.manage on the runtime client) exposes eight flat namespaces (one per resource family):

Namespace Resource
manage.contexts Context instances (register / list / get / delete)
manage.context_types Targeting-rule entity schemas
manage.environments Environments (built-ins + AD_HOC)
manage.account_settings Per-account settings
manage.config Smpl Config CRUD
manage.flags Smpl Flags CRUD
manage.loggers Smpl Logging logger CRUD
manage.log_groups Smpl Logging log-group CRUD

Configuration

All settings are resolved from three sources, in order of precedence:

  1. Constructor arguments — highest priority, always wins.
  2. Environment variables — e.g. SMPLKIT_API_KEY, SMPLKIT_ENVIRONMENT.
  3. Configuration file (~/.smplkit) — INI-format with profile support.
  4. Defaults — built-in SDK defaults.

Configuration File

The ~/.smplkit file supports a [common] section (applied to all profiles) and named profiles:

[common]
environment = production
service = my-app

[default]
api_key = sk_api_abc123

[local]
base_domain = localhost
scheme = http
api_key = sk_api_local_xyz
environment = development
debug = true

Constructor Examples

# Use a named profile
client = SmplClient(profile="local")

# Or configure explicitly
client = SmplClient(
    api_key="sk_api_...",
    environment="production",
    service="my-service",
)

For the complete configuration reference, see the Configuration Guide.

Error Handling

All SDK errors extend SmplError:

from smplkit import SmplError, SmplNotFoundError

try:
    config = mgmt.config.get("nonexistent")
except SmplNotFoundError:
    print("Config not found")
except SmplError as e:
    print(f"SDK error: {e}")
Exception Cause
SmplNotFoundError Resource not found
SmplConflictError Conflict (e.g., has children)
SmplValidationError Validation error
SmplTimeoutError Request timed out
SmplConnectionError Network connectivity issue
SmplError Any other SDK error

Debug Logging

Set SMPLKIT_DEBUG=1 to enable verbose diagnostic output to stderr. This is useful for troubleshooting real-time level changes, WebSocket connectivity, and SDK initialization. Debug output bypasses the managed logging framework and writes directly to stderr.

SMPLKIT_DEBUG=1 python my_app.py

Accepted values: 1, true, yes (case-insensitive). Any other value (or unset) disables debug output.

Documentation

License

MIT

Project details


Release history Release notifications | RSS feed

This version

3.2.0

Download files

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

Source Distribution

smplkit_sdk-3.2.0.tar.gz (280.3 kB view details)

Uploaded Source

Built Distribution

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

smplkit_sdk-3.2.0-py3-none-any.whl (432.5 kB view details)

Uploaded Python 3

File details

Details for the file smplkit_sdk-3.2.0.tar.gz.

File metadata

  • Download URL: smplkit_sdk-3.2.0.tar.gz
  • Upload date:
  • Size: 280.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for smplkit_sdk-3.2.0.tar.gz
Algorithm Hash digest
SHA256 45ce8f84983b0d66d3f7f037949b73b61cf96053a66e3957f08201591886c50e
MD5 f7d79921b517d8a057baa00cac6de952
BLAKE2b-256 c7cb65e4d2190998060710e3b0400bb169ae8a54ceff4eefefa27d57336ad66e

See more details on using hashes here.

Provenance

The following attestation bundles were made for smplkit_sdk-3.2.0.tar.gz:

Publisher: ci-cd.yml on smplkit/python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smplkit_sdk-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: smplkit_sdk-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 432.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for smplkit_sdk-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 460bf8ef36e61fb84ad079bea59338d3fb1d4af7161b1c40bb5a1294a64cd272
MD5 b0ecb04a66147093c404618cad988608
BLAKE2b-256 48ab0661d65c787eea20db570573bc794b00673005ff1e04e3144e2a32f80772

See more details on using hashes here.

Provenance

The following attestation bundles were made for smplkit_sdk-3.2.0-py3-none-any.whl:

Publisher: ci-cd.yml on smplkit/python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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