Skip to main content

Add your description here

Reason this release was yanked:

Packaging is broken

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.3.tar.gz (5.4 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.3-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyrachy-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2f41a40efb8d8b644850caf7a6f40a1666d38244a86a5c244cfb63c61bfd76fe
MD5 c5347ffec12788946e2343d8c73b6ca1
BLAKE2b-256 abfdd043d4b62c11dd5e72de6e94222715006520dc037389d6e6c1d07c30a858

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyrachy-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9afae13a5376e21a02fc24a344b34888582e596e966907053bbf91973cec0b18
MD5 7b15f0e4b3d474dde8460fbb74af660f
BLAKE2b-256 f54c777dcaecf8aa093da2f63d80f35a4209fd9fca5792a77ea72d42e2efea02

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