Metadata-Version: 2.3
Name: hiraconf
Version: 0.1.1
Summary: Hierarchical config parser
Project-URL: Repository, https://github.com/crxwns/HiraConf
Author: crxwns
License: MIT License
        
        Copyright (c) 2024 crxwns
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: pydantic>=2.8.2
Requires-Dist: pyyaml>=6.0.2
Description-Content-Type: text/markdown

# HiraConf

A hierarchical parser for configurations, allowing to merge or join configurations from multiple sources.

# Example

Using Pydantic for extracting the parsed configuration in this example, which is optional. You can also access the `data` property
to directly access the dictionary.


```python
from pydantic import BaseModel

from hiraconf.parser import Parser
from hiraconf.provider import TomlStringProvider, YamlStringProvider


# Create the BaseModels for validation of configuration
class Settings(BaseModel):
    debug: bool
    version: str
    new: int | None = None


class Config(BaseModel):
    settings: Settings


# Define your config as file, env, string, toml, yaml or any provider that implements the Provider ABC

yaml_settings = """settings:
  debug: true
  version: 1.0.0
  """

parsed_yaml = Parser().merge(YamlStringProvider(yaml_string=yaml_settings)).extract(Config)

print(parsed_yaml)
# >>> settings=Settings(debug=False, version='1.0.0', new=None)

# If you have multiple configs and want to merge those, you can. Like overwriting the debug setting.

toml_settings = """[settings]
debug = false
"""

parsed_merged = (
    Parser()
    .merge(YamlStringProvider(yaml_string=yaml_settings))
    .merge(TomlStringProvider(toml_string=toml_settings))
    .extract(Config)
)

print(parsed_merged)
# >>> settings=Settings(debug=False, version='1.0.0', new=None)

# Or you join it and keep the original value if it exists as is

toml_join_settings = """[settings]
debug = false
new = 10
"""

parsed_joined = (
    Parser()
    .merge(YamlStringProvider(yaml_string=yaml_settings))
    .join(TomlStringProvider(toml_string=toml_join_settings))
    .extract(Config)
)

print(parsed_joined)
# >>> settings=Settings(debug=True, version='1.0.0', new=10)
```

# Provider

You can define your own `Provider` by inheriting from `Provider` and implementing the abstract `load(self) -> dict[str, Any]` method.