Config is a Python module that provides a hierarchical, easy-to-use, and powerful configuration scheme. It supports mappings, sequences, cross-references between configuration parts, flexible access to Python objects, includes, simple expression evaluation, and the ability to change, save, cascade, and merge configurations. It also interfaces easily with environment variables and command-line options. The current version is 0.5.1 and it appears to be actively maintained, with the latest release in September 2021 and recent mentions in 2025-2026 as stable.
pip install configVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load a configuration from a file using the `Config` class. It shows how to define sections, key-value pairs, references to other configuration values (e.g., `base_url`), and how to inject values from environment variables (e.g., `DB_USER`, `DB_PASSWORD`) with optional default fallbacks.
Review and update existing `.cfg` files to conform to the latest CFG format syntax, particularly for boolean/null literals and cross-reference patterns.
Always ensure configuration files come from trusted sources. Sanitize or validate complex configuration values if there's any doubt about their origin or content. Avoid allowing arbitrary object instantiation or method calls if security is paramount and config sources are not fully controlled.
Utilize environment variables (e.g., `os.environ.get('SECRET_KEY')`) or a dedicated secret management solution for sensitive data. Use environment variable fallbacks in your configuration files as demonstrated in the quickstart (e.g., `password: ${DB_PASSWORD|}`).Install the package using `pip install config`. If the package is already installed, check your project directory and Python path for any local files or folders named 'config' and rename them to avoid conflicts. Ensure your virtual environment is activated if you are using one.
Correctly import the `Configuration` class from the `config.config` submodule: `from config.config import Configuration`. Then, instantiate it as `cfg = Configuration()` and load your configuration files, for example, `cfg.add_file('your_config.ini')`.Verify that 'your_config_key' is correctly defined in your configuration file (e.g., `your_config.ini`, `your_config.json`, or a dictionary used to initialize `Configuration`). To safely access optional configuration items, use the `get()` method with a default value, like `value = cfg.get('your_config_key', 'default_value')`.No dependency data recorded yet.