Skip to content

OpenDecree Python SDK

CI PyPI Python License

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

Requirements

  • Python 3.11+
  • A running OpenDecree server (v0.8.0 – v0.x, pre-1.0)

Quick Start

from opendecree import ConfigClient

with ConfigClient("localhost:9090", subject="myapp") as client:
    # Get a config value (returns str by default)
    fee = client.get("tenant-id", "payments.fee")

    # Typed reads — pass the target type
    retries = client.get("tenant-id", "payments.retries", int)
    enabled = client.get("tenant-id", "payments.enabled", bool)

    # Write a value
    client.set("tenant-id", "payments.fee", "0.5%")

The with block manages the gRPC channel lifecycle — it opens on enter and closes on exit.

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}")

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 are available in the examples/ directory of the repository.

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

Next Steps

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