Skip to content

Python API

import detent

The detent extension module is built with pybind11 when DETENT_BUILD_PYTHON=ON.


detent.Client(
defaults_path: str,
source_path: str | None = None,
cli_overrides: list[str] = [],
poll_interval_ms: int = 200,
)

Constructs a client with the given baked defaults and, optionally, a file source. Raises detent.DetentError for missing or invalid defaults and invalid CLI overrides.

Client.get(name: str, hash_val: str | None = None, switch_val: str | None = None) -> int

Reads a knob’s int64 value with the standard precedence.

Client.get_bool(name: str, hash_val: str | None = None, switch_val: str | None = None) -> bool

Calls get, then returns False for 0 and True for 1. Any other value raises detent.DetentError with category ConversionFailed.

Client.health() -> dict
{'initialized': True, 'source_connected': True, 'accepted_version': 7,
'staleness_seconds': 0.4, 'knobs': 3, 'cli_overrides': 0}

Raised for every construction and read failure. The message starts with the error category:

try:
client.get("search:nope")
except detent.DetentError as e:
print(e) # MissingKnob: search:nope (not present in current snapshot)

Reads are in-memory and non-blocking.