Skip to main content

Add your description here

Reason this release was yanked:

Incorrect documentation

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

  • ArgLoader: 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 = ArgLoader(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.4.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.4-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyrachy-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 62d3f5e2071943b14b07928ec7febe1ccd0220f4ba47a218797726253385af40
MD5 32aa4b06f90e86933a5bf5e437ca8acf
BLAKE2b-256 32dc97d4d5d4d8f3a338dc831cd5f3abc054ba60ebe7ce3978928ed4cf73427b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyrachy-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e6de1ba6f25d2035964942b8b6593e5ed681a5b1ff55752f786dd811116fe565
MD5 5d2a1e92b265108cbd1cc2a130ab48e1
BLAKE2b-256 35679c29ef2232e1699f23f478b95d32f227a6d7c2fa1e7efc2a0b6835edc5cf

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