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.0.tar.gz (8.1 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.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file loadcfg-0.1.0.tar.gz.

File metadata

  • Download URL: loadcfg-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 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.0.tar.gz
Algorithm Hash digest
SHA256 02bc13bf312e25dfd0de88eb05fd8685140de93add287c888fe75954e5f52994
MD5 a736a7fe325c4306bcffa5a37ac2c544
BLAKE2b-256 2d65e1a000bf065da89f00ac0d13d97e0ab89bd40c8f50429586e1dd68f56ea9

See more details on using hashes here.

File details

Details for the file loadcfg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: loadcfg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94a6e78c901f88f77308e6d398032d87c1a24f2a43f9d2d74efe77816322b526
MD5 bed41a2f16da0fe43a12d6bc667ac745
BLAKE2b-256 21051b77ba0a8ccad4ec0de6f33d563dfaaef525829bdf5eaefc4e8a5950393d

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