PriorityPolicy

Priority policy for configuration sources.

Defines how sources are ordered and merged, with support for per-key priority rules.

class varlord.policy.PriorityPolicy(default, overrides=None)[source]

Bases: object

Defines priority ordering for configuration sources.

Supports: - Default priority for all keys - Per-key/namespace overrides using pattern matching - Source ID (exact match) or name (match all of type)

Example

>>> policy = PriorityPolicy(
...     default=["defaults", "dotenv", "env", "cli"],
...     overrides={
...         "secrets.*": ["defaults", "etcd", "env"],  # Different rules for secrets
...     }
... )
>>> # Using source ID for exact match:
>>> policy = PriorityPolicy(
...     default=["defaults", "yaml:/etc/config.yaml", "yaml:~/.config/app.yaml", "env", "cli"],
... )
>>> # Using source name to match all of type:
>>> policy = PriorityPolicy(
...     default=["defaults", "yaml", "env", "cli"],  # All yaml sources before env
... )
>>> # Mixed usage:
>>> policy = PriorityPolicy(
...     default=["defaults", "yaml:/etc/config.yaml", "yaml", "env", "cli"],
...     # First specific system config, then all other yaml sources, then env and CLI
... )
default: List[str]

Default priority order for all keys.

Can contain: - Source IDs (exact match, e.g., “yaml:/etc/config.yaml”) - Source names (match all of type, e.g., “yaml”)

overrides: Dict[str, List[str]] | None = None

Per-key priority overrides.

Keys are glob patterns (e.g., “secrets.*”, “db.*”). Values are priority lists for matching keys. Can contain source IDs or names (same as default).

__init__(default, overrides=None)
get_priority(key)[source]

Get priority order for a specific key.

Parameters:

key (str) – Configuration key (e.g., “db.host”, “secrets.api_key”)

Returns:

List of source IDs or names in priority order (highest to lowest). - Source ID (e.g., “yaml:/etc/config.yaml”): Exact match - Source name (e.g., “yaml”): Match all sources with this name

Return type:

List[str]

__repr__()[source]

Return string representation.