Skip to content

opendecree/decree-python

OpenDecree Python SDK

CI PyPI Python Downloads License Project Status: WIP codecov Docs Open in GitHub Codespaces

Python SDK for OpenDecree — schema-driven configuration management.

Alpha — This SDK is under active development. APIs and behavior may change without notice between versions.

Install

pip install opendecree

Quick Start

from opendecree import ConfigClient

with ConfigClient("localhost:9090", subject="myapp") as client:
    # Get config values (default: string)
    fee = client.get("tenant-id", "payments.fee")

    # Typed gets via overload
    retries = client.get("tenant-id", "payments.retries", int)
    enabled = client.get("tenant-id", "payments.enabled", bool)

    # Set values
    client.set("tenant-id", "payments.fee", "0.5%")

Watch for Changes

with ConfigClient("localhost:9090", subject="myapp") as client:
    with client.watch("tenant-id") as watcher:
        fee = watcher.field("payments.fee", float, default=0.01)
        enabled = watcher.field("payments.enabled", bool, default=False)

        if enabled:
            print(f"Current fee: {fee.value}")

        @fee.on_change
        def on_fee_change(old: float, new: float):
            print(f"Fee changed: {old} -> {new}")

Fork safety: gRPC channels are not fork-safe. Create ConfigClient (and start any watcher) after forking — not before. See Fork safety for details.

Async

from opendecree import AsyncConfigClient

async with AsyncConfigClient("localhost:9090", subject="myapp") as client:
    val = await client.get("tenant-id", "payments.fee")
    retries = await client.get("tenant-id", "payments.retries", int)

Examples

Runnable examples in the examples/ directory:

Example What it shows
quickstart Context manager, typed get(), set()
async-client async with, await, asyncio.gather()
live-config ConfigWatcher, @on_change, changes()
fastapi-integration Async watcher as FastAPI lifespan dependency
error-handling RetryConfig, nullable=True, error hierarchy

Documentation

For detailed concepts (schemas, typed values, versioning, auth), see the main OpenDecree docs.

Supply Chain Security

Each release wheel is signed with Sigstore via the GitHub Actions OIDC identity. Attestations are visible on the PyPI project page.

To verify a downloaded wheel locally:

pip download opendecree --no-deps
gh attestation verify opendecree-*.whl --repo opendecree/decree-python

See decree#16 for the org-wide attestation plan.

Requirements

  • Python 3.11+
  • A running OpenDecree server (v0.3.0+)

Questions?

Head to OpenDecree Discussions — our community hub covers all OpenDecree repos.

License

Apache License 2.0 — see LICENSE.

Packages

 
 
 

Contributors