chz: Configuration Management
chz (pronounced "चीज़") is a Python library designed for managing configuration, particularly from the command line. It features a declarative object model, immutability, validation, and type checking. Currently at version 0.4.0, it appears to have a relatively active release cadence with several updates in the past year.
Warnings
- gotcha chz objects are designed to be immutable; you cannot reassign fields after creation. This is a deliberate design choice to prevent certain classes of configuration bugs. If you find yourself frequently needing to modify configurations, consider using `Blueprint`'s partial application features or creating new instances instead of trying to mutate existing ones.
- gotcha Users new to `chz.Blueprint` might experience a learning curve, particularly with concepts like partial application and how configurations are built up. The power comes from its flexibility in defining and combining configuration parts, but this can be unfamiliar initially.
- breaking The `CHANGELOG.md` indicates significant internal refactoring, especially around `blueprint` and `meta_factory` unification in March 2025 and November 2024. While direct user-facing API changes are not explicitly flagged as 'breaking' for stable releases, these internal shifts suggest that relying on undocumented internal behaviors could lead to breakage in minor or patch releases.
Install
-
pip install chz
Imports
- Blueprint
from chz import Blueprint
- Field
from chz import Field
Quickstart
from chz import Blueprint, Field
class Config(Blueprint):
name: str = Field(default='World', help='The name to greet')
loud: bool = Field(default=False, help='Whether to shout the greeting')
def main(config: Config):
greeting = f'Hello, {config.name}!'
if config.loud:
greeting = greeting.upper()
print(greeting)
if __name__ == '__main__':
# Example of how to run from a script with overrides
# In a real CLI, this would be parsed from command-line arguments
# To simulate command line: python your_script.py --name Alice --loud
# Or, using the Blueprint directly for programmatic use:
try:
# Simulate parsing command line arguments or provide defaults
# For simplicity in quickstart, directly create a config instance.
# In a CLI application, you'd use Blueprint.apply_args() or similar.
my_config = Config(name='Registry', loud=True)
main(my_config)
except Exception as e:
print(f"Error running quickstart: {e}")