Skip to main content

Add your description here

Project description

Pyrachy - Hierarchical Config Loader

This Python package provides a flexible, pluggable configuration system that loads configuration from multiple sources such as command-line arguments, environment variables, and files (YAML, TOML, etc.). It is designed to support hierarchical configuration structures, making it easy to manage complex configurations in your Python projects.

Features

  • Hierarchical Configuration: Supports nested configuration values for more complex setups.
  • Pluggable Loaders: Easily extendable system with support for multiple configuration sources such as command-line arguments, environment variables, and files.
  • Extensible: Freedom to create your own loaders which can load config from anywhere.

Usage

  1. Define Loaders The core of the system is the loader class that fetches the configuration from various sources. Each loader implements the BaseLoader class and is responsible for loading the configuration from a specific source.

Included Loaders

  • ArgvLoader: Loads configuration from command-line arguments.
  • EnvLoader: Loads configuration from environment variables.
  • FileLoader: Loads configuration from files (YAML, TOML, JSON).
  1. Create the Config Object You can create a Config object and pass a list of loaders. The Pyrachy class will try to load the configuration from each of the defined loaders and merge them into a single configuration, from right to left

Example

from pyrachy import Pyrachy, ArgLoader, EnvLoader, FileLoader

# Create the loaders
arg_loader = ArgvLoader(allowed_args=['db-host', 'db-port'], separator='-')
env_loader = EnvLoader(prefix="MY_APP_", separator='_')
file_loader = FileLoader(file_paths=['config.yaml'])

# Create the Config object and load the configuration
config = Pyrachy([   
    file_loader,
    arg_loader, 
    env_loader, 
])
loaded_config = config.get()

print(loaded_config)

In this example, the Config object will load configuration values from:

  1. Environment variables: e.g., MY_APP_db_port=5433
  2. Command-line arguments: e.g., --db-host=remote --db-port=5432
  3. YAML file: e.g., a file config.yaml with contents:
db:
  host: localhost
  port: 5432
  dbname: test

The result will be a single merged configuration:

{
  'db': {
    'host': 'remote',
    'port': '5433',
    'dbname': 'test'
  }
}

Custom Loaders

You can easily extend this package by adding custom loaders. Each loader should inherit from the BaseLoader class and implement the load() method.

from Pyrachy import BaseLoader

class CustomLoader(BaseLoader):
    def load(self) -> dict[str, Any]:
        # Custom logic to load configuration
        return {'custom': {'value': 'example'}}

Contributing

We welcome contributions to improve the project! Please follow these guidelines to get started:

1. Fork the repository

Start by forking the repository to your own GitHub account. This will allow you to make changes and submit a pull request.

2. Install dependencies

Make sure you have all required development dependencies installed. This project uses uv for dependency management

To install it, you can run: pipx install uv

Then run uv sync to install required packages

3. Make your changes

Implement your changes or improvements. Ensure your code adheres to the project's style guide and that any new features are thoroughly tested.

4. Write tests

Add tests for any new features or changes. We use pytest for testing, so please ensure that your tests are written with pytest.

You can run the tests using pytest. The tests cover the core functionality and ensure that the loaders work correctly with different configuration sources.

uv run task test

5. Commit your changes

Commits MUST follow the Conventional Commits standard. Example commit types include:

  • feat: A new feature
  • fix: A bug fix
  • chore: Routine tasks like updates to dependencies or documentation
  • docs: Changes to documentation
  • style: Code style improvements (e.g., formatting, linting)
  • test: Adding or improving tests
  • refactor: Refactoring code without changing functionality

This repo includes commitizen to help you write conventional commits

6. Create a pull request

Open a pull request from your branch to the main branch of the original repository. Provide a detailed description of the changes and why they are needed.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrachy-0.1.5.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrachy-0.1.5-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file pyrachy-0.1.5.tar.gz.

File metadata

  • Download URL: pyrachy-0.1.5.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.24

File hashes

Hashes for pyrachy-0.1.5.tar.gz
Algorithm Hash digest
SHA256 43e9216249cec7f8ac6c601edf86e73a08a3aae9a4aca8e9a8afb2c72ba3a13f
MD5 f997f105a87ab3479fef726ee38da413
BLAKE2b-256 6dd0a9d64f6d10820b442d299914778247abecd662178d8f0265ca26e2f6f274

See more details on using hashes here.

File details

Details for the file pyrachy-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: pyrachy-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.24

File hashes

Hashes for pyrachy-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 20040cf7f79522967748742e94eae17219e7f8a525a9cf4dcc1d2e366d864213
MD5 797d293b2120b21090c2c462e4b231e9
BLAKE2b-256 4061cd61a302c14fdbe18d6a29eef9aa39b0272a840c4d1214bfb7101266562f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page