Skip to main content

Schema-bound configuration engine for human-edited application config files.

Project description

BoundConfig

BoundConfig manages a TOML config file against one or more TOML defaults files. The current implementation can:

  • add missing managed keys and sections with init
  • validate managed content without writing with validate
  • repair missing or invalid managed content through the Python API with repair

Unknown user keys and sections are preserved during managed operations. Writes go through tomlkit, so comments and ordering survive as well as that adapter allows.

Current Public Surface

  • CLI commands: boundconfig init, boundconfig validate
  • Python API: boundconfig.BoundConfig, boundconfig.register_validator
  • TOML only
  • Python 3.10+

repair exists today, but only through the Python API. There is no CLI repair subcommand in the current implementation.

Current Limits

  • Defaults files must use top-level TOML sections only.
  • Managed nested tables and arrays of tables in defaults files are out of scope.
  • Managed inline-table defaults are validated only shallowly for table shape.
  • There is no CLI hook for registering custom validators.
  • Offset time values are not supported. Use TOML local time values instead.

Install From A Clone

python -m pip install -e .

After installation, the console script is boundconfig. The module entry point also works:

python -m boundconfig --help

Quick Start

The sample set under samples/ is verified against the current test suite. The shortest walkthrough is samples/basic/.

Given a defaults file and a working config:

[service]
enabled = true
retries = 3
mode = { _default_value = "INFO", _allowed_values = ["DEBUG", "INFO"] }
point = { x = 1, y = 2 }

[ui]
theme = "dark"
[service]
enabled = "true"
mode = "DEBUG"
extra = "user"

[custom]
feature = true

Run init to add only missing managed content:

boundconfig init --config ./config.toml --defaults ./defaults.toml --verbose

Run validate to see what is still wrong:

boundconfig validate --config ./config.toml --defaults ./defaults.toml --verbose

Repair invalid managed values through the Python API:

from pathlib import Path

from boundconfig import BoundConfig

bound_config = BoundConfig(
    config_path=Path("config.toml"),
    defaults_paths=(Path("defaults.toml"),),
)

report = bound_config.validate()
repaired_document = bound_config.repair(dry_run=True)

init does not repair existing invalid managed values. repair does.

Guides

Custom Validators

Custom validators are implemented, but the feature is intentionally narrow. A schema can bind a field to a validator name with _validator, and Python code can register a callable under that name.

[service]
name = { _default_value = "BoundConfig", _validator = "no-spaces" }
from pathlib import Path

from boundconfig import BoundConfig

bound_config = BoundConfig(
    config_path=Path("config.toml"),
    defaults_paths=(Path("defaults.toml"),),
)
bound_config.register_validator(
    "no-spaces",
    lambda value: "must not contain spaces" if " " in value else None,
)

report = bound_config.validate()

There is no CLI flag, plugin system, or import hook for validator registration in the current implementation. If a defaults file uses _validator, the CLI will only work if some wrapper code has already registered that validator in the current Python process.

See samples/custom-validator/ for matching example files.

Notes On CLI Options

The CLI currently exposes the same option set on both subcommands because they share an argument parser:

  • --config
  • --defaults
  • --dry-run
  • --verbose
  • --suppress-warnings

Only part of that surface matters per command today:

  • init uses --dry-run and --verbose. --suppress-warnings is accepted but has no effect.
  • validate uses --verbose and --suppress-warnings. --dry-run is accepted but redundant because validate never writes.
  • --defaults can be repeated or given multiple paths after one flag.

Project details


Download files

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

Source Distribution

boundconfig-0.1.0.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

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

boundconfig-0.1.0-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file boundconfig-0.1.0.tar.gz.

File metadata

  • Download URL: boundconfig-0.1.0.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for boundconfig-0.1.0.tar.gz
Algorithm Hash digest
SHA256 abbc2259765e3fd323e6b392dcae7758e066366db85604886e8c372199388a59
MD5 958cdcbf7c928edd85e0252a57c84f7b
BLAKE2b-256 100a0ed8d7de7b870fc899dfc04a6394fe1e7bf5689eb1d4d7bb120d2632f4b6

See more details on using hashes here.

File details

Details for the file boundconfig-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: boundconfig-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for boundconfig-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5099d3032e2986e2f847506e13fc232a4f9b032c1e9d2ddd6dafbc9d310b63d9
MD5 263ea8677f7c0e9c788ac8d6a15b3767
BLAKE2b-256 c1a6a93e655061cfcf353e259c49f0fc02d14579b85c2aa2c2668c8639be87ec

See more details on using hashes here.

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