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)
Metadata
Release files for loadcfg 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 | |
|---|---|---|---|
| loadcfg-0.1.1.tar.gz | 9.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| loadcfg-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.2 kB
Release files / loadcfg-0.1.1.tar.gz
| Download URL | loadcfg-0.1.1.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7257f4b5a936c0ef844a39a773ef6d7ab5a6cab8b86de9755924080196ae58f1
|
|
BLAKE2b-256 checksum How to use checksums |
499f832a4836755a9e52bdbc06eebe6c436bf37cdc01850f8ac46b78771c0f43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Release files / loadcfg-0.1.1-py3-none-any.whl
| Download URL | loadcfg-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4367061f17b169b4cfdad1d1a4af262856f4f761a8d1557a0d9e064d28f31c7d
|
|
BLAKE2b-256 checksum How to use checksums |
afd1ef7847f85d5d545b854cea051c61e766558c945e73c86ad87cff67a9a84e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|