A configuration helper library for JSON and YAML config files with dot-access.
Project description
loadcfg
loadcfg is a lightweight Python library that makes it easy to load configuration files in JSON and YAML formats with convenient dot-access to configuration values.
- Install with:
pip install loadcfg - License: MIT License
- Maintained by: Daniel Korkin (daniel.d.korkin@gmail.com)
- Library Purpose: Easily load and validate configuration files (JSON and YAML)
- Documentation: loadcfg.readthedocs.io
- Code Coverage: Codecov Dashboard
- GitHub Repository: github.com/danielkorkin/loadcfg
- PyPI: pypi.org/project/loadcfg
Example Usage
from loadcfg import LoadJson, LoadYaml, Template, ConfigValidationError
# --- Loading a configuration file ---
config = LoadJson("config.json")
print(config.name) # Access via attribute notation.
print(config.info.age)
# --- Defining a configuration template ---
class ProgramConfig(Template):
name: str
age: int
# You can also define nested templates:
# details: OtherTemplate
# Validate a loaded configuration
try:
ProgramConfig.validate(config)
except ConfigValidationError as err:
print("Configuration error:", err)
# Alternatively, validate directly from the config instance:
config.validate(ProgramConfig)
# --- Generating an example configuration ---
example_json = ProgramConfig.generate(fmt="json")
print(example_json)
example_yaml = ProgramConfig.generate(fmt="yaml")
print(example_yaml)
Testing
This library uses pytest for testing. To run tests locally, use:
pytest
Contributing
Contributions are encouraged and appreciated! Feel free to submit issues and pull requests on GitHub.
License
This project is licensed under the MIT License.
Contact
Maintained by Daniel Korkin (daniel.d.korkin@gmail.com)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file loadcfg-0.1.1.tar.gz.
File metadata
- Download URL: loadcfg-0.1.1.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7257f4b5a936c0ef844a39a773ef6d7ab5a6cab8b86de9755924080196ae58f1
|
|
| MD5 |
3d8faa969a7f1293911478faa04ad822
|
|
| BLAKE2b-256 |
499f832a4836755a9e52bdbc06eebe6c436bf37cdc01850f8ac46b78771c0f43
|
File details
Details for the file loadcfg-0.1.1-py3-none-any.whl.
File metadata
- Download URL: loadcfg-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4367061f17b169b4cfdad1d1a4af262856f4f761a8d1557a0d9e064d28f31c7d
|
|
| MD5 |
294bdf82ad28ce585021b269a77e95e9
|
|
| BLAKE2b-256 |
afd1ef7847f85d5d545b854cea051c61e766558c945e73c86ad87cff67a9a84e
|