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_keysfor 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file configurize-0.2.0.tar.gz.
File metadata
- Download URL: configurize-0.2.0.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37268bd45549afb911c00ef60e6e9c78155e06abef52057d3eb28f53089d00db
|
|
| MD5 |
67437cf33b5d245e026415bfcde27004
|
|
| BLAKE2b-256 |
670199b885ed1d892a45d72a363d900034b27560b98cfb7e02ae90ed5fa9b327
|
Provenance
The following attestation bundles were made for configurize-0.2.0.tar.gz:
Publisher:
publish.yml on Randomizez/configurize
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
configurize-0.2.0.tar.gz -
Subject digest:
37268bd45549afb911c00ef60e6e9c78155e06abef52057d3eb28f53089d00db - Sigstore transparency entry: 942899728
- Sigstore integration time:
-
Permalink:
Randomizez/configurize@858f55b589e3768adf4cd80b339f1c76a65792e6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Randomizez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@858f55b589e3768adf4cd80b339f1c76a65792e6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file configurize-0.2.0-py3-none-any.whl.
File metadata
- Download URL: configurize-0.2.0-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bd3f259b8c044e939b555f602d5bfd16082b543dd4399bc0e4e2f9b3cb35054
|
|
| MD5 |
dbd3dc3be26ffd914168ccbdf2d586c0
|
|
| BLAKE2b-256 |
2ef7b212b1ffce43954d0afe3da50fa9e9742ed6841a9b8689620b3efadeaec8
|
Provenance
The following attestation bundles were made for configurize-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on Randomizez/configurize
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
configurize-0.2.0-py3-none-any.whl -
Subject digest:
2bd3f259b8c044e939b555f602d5bfd16082b543dd4399bc0e4e2f9b3cb35054 - Sigstore transparency entry: 942899735
- Sigstore integration time:
-
Permalink:
Randomizez/configurize@858f55b589e3768adf4cd80b339f1c76a65792e6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Randomizez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@858f55b589e3768adf4cd80b339f1c76a65792e6 -
Trigger Event:
push
-
Statement type: