Configuration Library Wrappers

0.0.1 · active · verified Mon Apr 13

This library, referred to as 'configs' on GitHub, provides wrappers for handling configuration through JSON, YAML, environment variables, and command-line arguments. It aims to simplify the process of loading and accessing hierarchical configuration settings. It is currently at version 0.0.1, indicating an early development stage with an infrequent release cadence.

Warnings

Install

Imports

Quickstart

Initializes the Config object, which by default attempts to load `config.json` or `config.yaml` from the current directory, and also processes environment variables. Configuration values are accessible via attribute access or a dictionary-like `get` method.

import os
from configs.config import Config

# Create a dummy config.json file for demonstration
with open('config.json', 'w') as f:
    f.write('{"database": {"host": "localhost", "port": 5432}}')

# Set an environment variable (optional)
os.environ['APP_ENV'] = 'development'

# Initialize Config - it will look for config.json or config.yaml by default
# in the current directory, and also process environment variables.
# For demonstration, we explicitly pass a config file path or let it discover.
# In a real app, you might pass sys.argv for argparse processing.

# Example 1: Load from default config.json
app_config = Config()

print(f"DB Host: {app_config.database.host}")
print(f"DB Port: {app_config.database.port}")
print(f"App Environment (from env var): {app_config.app_env}")

# Example 2: Accessing values dynamically or with a default
port_value = app_config.get('database.port', default=5432)
print(f"DB Port (via .get() with default): {port_value}")

# Clean up dummy file and env var
os.remove('config.json')
del os.environ['APP_ENV']

view raw JSON →