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.
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.
Metadata
Release files for hiraconf 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hiraconf-0.1.1.tar.gz | 14.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hiraconf-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.3 kB
Release files / hiraconf-0.1.1.tar.gz
| Download URL | hiraconf-0.1.1.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f248e3ddc9d6e3ce4a3f81a82dc20e14de42a2cfa71ede30aa65b2f3fa15efb
|
|
BLAKE2b-256 checksum How to use checksums |
42bb667f3bde6bfd50484e5a169b894e425e9186968946cf09fb782f3df87c85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Release files / hiraconf-0.1.1-py3-none-any.whl
| Download URL | hiraconf-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8f68f8d188d319465b5d0b45ef21682c659c95f7b9bd41c73b8f14d1370e05f
|
|
BLAKE2b-256 checksum How to use checksums |
17cf0c3706753e0fcd783dd613de7da4726d29c3fb69fad35b17e522644d35ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|