Skip to main content

A configuration helper library for JSON and YAML config files with dot-access.

Project description

loadcfg

GitHub Actions Workflow Status PyPI - Version Codecov Read the Docs PyPI - License PyPI - Python Version GitHub last commit

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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loadcfg-0.1.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loadcfg-0.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

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

Hashes for loadcfg-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7257f4b5a936c0ef844a39a773ef6d7ab5a6cab8b86de9755924080196ae58f1
MD5 3d8faa969a7f1293911478faa04ad822
BLAKE2b-256 499f832a4836755a9e52bdbc06eebe6c436bf37cdc01850f8ac46b78771c0f43

See more details on using hashes here.

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

Hashes for loadcfg-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4367061f17b169b4cfdad1d1a4af262856f4f761a8d1557a0d9e064d28f31c7d
MD5 294bdf82ad28ce585021b269a77e95e9
BLAKE2b-256 afd1ef7847f85d5d545b854cea051c61e766558c945e73c86ad87cff67a9a84e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page