Skip to main content

Hierarchical configuration management with inheritance, cross-references, and diffing

Project description

Configurize

A Python library for hierarchical configuration management with inheritance, cross-references, and diffing support.

Installation

pip install configurize

for development

pip install .

Features

  • Hierarchical configs: Nest configs within configs with automatic parent-child relationships
  • Inheritance: Extend configs like regular Python classes
  • Cross-references: Use Ref() to reference values from other parts of the config tree
  • Diffing: Compare two configs and see what changed
  • Merge: Apply updates from dicts or other configs
  • Validation: Define critical_keys for consistency checks

Quick Start

from configurize import Config, Ref

class ModelConfig(Config):
    in_channels = 32
    out_channels = 64

class TrainerConfig(Config):
    train_iters = 100
    batch_size = 16

class Exp(Config):
    model = ModelConfig
    trainer = TrainerConfig

# Create and use
exp = Exp()
print(exp.model.in_channels)  # 32
print(exp.trainer.train_iters)  # 100

Cross-References with Ref

Use Ref() to reference values from other parts of the config tree:

class ModelConfig(Config):
    hidden_dim = Ref('..hidden_dim')  # Reference parent's hidden_dim

class Exp(Config):
    hidden_dim = 256
    model = ModelConfig

exp = Exp()
print(exp.model.hidden_dim)  # 256 (resolved from parent)

Reference syntax:

  • .attr - self.attr
  • ..attr - parent.attr
  • ...sub.attr - grandparent.sub.attr

Merging and Overrides

exp = Exp()

# Merge from dict (supports dot notation)
exp.merge({'model.in_channels': 64, 'trainer.train_iters': 200})

# Temporary modifications
with exp.trainer.modify(batch_size=32):
    print(exp.trainer.batch_size)  # 32
print(exp.trainer.batch_size)  # 16 (restored)

Diffing Configs

exp1 = Exp()
exp2 = Exp()
exp2.model.in_channels = 128

diff = exp1.diff(exp2)
print(diff)  # Shows differences with colors

CLI Tool

After installation, use cfshow to inspect and compare config files:

# Show a config
cfshow examples/train_example.py

# Compare two configs
cfshow base_exp.py new_exp.py

# Inspect a sub-config
cfshow my_exp.py --key=model

Example

See examples/train_example.py for a complete example showing:

  • Nested config structure (logger, model, trainer)
  • Builder pattern with build_* methods
  • Running an experiment from config

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

configurize-0.1.3.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

configurize-0.1.3-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file configurize-0.1.3.tar.gz.

File metadata

  • Download URL: configurize-0.1.3.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for configurize-0.1.3.tar.gz
Algorithm Hash digest
SHA256 48aeaab06034f62c5d8ae5400e9deb15bcd27a608b960c8c66301bf943e19fc9
MD5 4575a1b8828f0c88d8f6e119ea6a9453
BLAKE2b-256 5e3ef01905a78c8bd1b79050128fd14da8054b28b28a4094475593dd817f9b68

See more details on using hashes here.

Provenance

The following attestation bundles were made for configurize-0.1.3.tar.gz:

Publisher: publish.yml on Randomizez/configurize

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file configurize-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: configurize-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for configurize-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6b7a388f1bdc6b67c3ab2ed914ae7ce01c47148ae7bf7c1f360df3760d608ec3
MD5 9e05945b32fa0e4ca0f7c10cd9db9e1e
BLAKE2b-256 605a7605f53c5a9c19cc4b86d05ced120057ecd9d8f6c898fb9055a8af5de672

See more details on using hashes here.

Provenance

The following attestation bundles were made for configurize-0.1.3-py3-none-any.whl:

Publisher: publish.yml on Randomizez/configurize

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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