https://github.com/gieseladev/konfi
Config parser
https://github.com/gieseladev/konfi
config python-library
Last synced: 5 months ago
JSON representation
Config parser
- Host: GitHub
- URL: https://github.com/gieseladev/konfi
- Owner: gieseladev
- License: mit
- Created: 2019-06-27T13:14:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-03T03:53:05.000Z (almost 2 years ago)
- Last Synced: 2025-12-02T03:17:20.994Z (6 months ago)
- Topics: config, python-library
- Language: Python
- Homepage: https://giesela.dev/konfi
- Size: 153 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# konfi
[](https://circleci.com/gh/gieseladev/konfi)
[](https://pypi.org/project/konfi/)
[](https://konfi.giesela.dev/en/latest/?badge=latest)
konfi lets you create config templates similar to
[dataclasses](https://docs.python.org/3/library/dataclasses.html).
These templates are then used to load the config from different sources.
konfi guarantees that the loaded config corresponds to the template even
going as far as making sure items of a list are of the right type.
This means you no longer have to worry about the validity of the config,
if the config is correct it will load and if it isn't it will raise an
error telling you why not.
## Installation
You can install konfi from [PyPI](https://pypi.org/project/konfi/):
```bash
pip install konfi
```
## Example
```python
from typing import Optional
import konfi
@konfi.template()
class UserInfo:
name: str
country: Optional[str]
@konfi.template()
class AppConfig:
name: str = "konfi"
user: UserInfo
konfi.set_sources(
konfi.YAML("config.yml", ignore_not_found=True),
konfi.Env(prefix="app_"),
)
config = konfi.load(AppConfig)
greeting = f"Hello {config.user.name}"
if config.user.country:
greeting += f" from {config.user.country}"
print(greeting)
print(f"Welcome to {config.name}!")
```
For more examples see the [examples/](examples) directory.
## Documentation
If you're ready to jump in, you can find the documentation on
[Read the Docs](https://konfi.giesela.dev).