chz: Configuration Management

0.4.0 · active · verified Tue Apr 14

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

Install

Imports

Quickstart

This quickstart defines a simple configuration using a `chz.Blueprint` class with `Field`s for type hints, defaults, and help text. It then shows how to use this configuration in a `main` function. In a command-line scenario, `chz` would automatically parse arguments into this `Config` object. For programmatic use, you can instantiate `Config` directly.

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}")

view raw JSON →