Skip to main content

yaconfig

Github release PyPI

license MIT

Build Status

Python package to assist configuration of Python software.

Installation

To install the latest release:

pip3 install yaconfig

Usage

This package is intended to be used by other packages to assist in their configuration. The recommended workflow follows:

  • Add a config module. Its purpose should be to define the configuration variables (the metaconfig) and to provide a single instance of the actual configuration (the values) for your application. Simple example:
"""File config.py"""
import yaconfig

metaconfig = yaconfig.MetaConfig(
    yaconfig.Variable("text", type=str, default="Hello world", help="Text to output")
)


# Get a default configuration...
config = yaconfig.Config(metaconfig)

# ... and override it with that in the config file
try:
    config.load_json("config.json")
except FileNotFoundError:
    pass

# You can also write initialization code if running the module
def main():
    metaconfig.interactive_json("config.json")


if __name__ == "__main__":
    main()
  • To access the variables, just use the config instance. Example:
"""File main.py"""
from config import config  #from .config import config if running in a package

print(config["text"])
  • In-code modification of the variables is also possible, as in config["text"]="howdy!", but bear in mind that initialization code that used the previous value is not reloaded. Also, you have to provide a string representation of the value, as in config["number"]="5". This is intended to enforce the same behavior as when loading from text files.

  • To document the configuration, you can use the methods of the metaconfig variable you have defined. This can be done manually from the interpreter or automated by writing a script, as in the main method in the config module example. The methods available include:

from config import metaconfig # Or wherever the config was placed

metaconfig.generate_json_example()  # Generate a config.example.json file
metaconfig.generate_environment_example()  # Generate a environment.example.sh file
metaconfig.interactive_json()  # Prompt the user to generate a config.json file
metaconfig.interactive_environment()  # Prompt the user to generate a environment.sh file

Metadata

Release files for yaconfig 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yaconfig 0.6.1
File Size Uploaded
yaconfig-0.6.1.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yaconfig 0.6.1
File Interpreter ABI Platform
yaconfig-0.6.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 13.0 kB

Release files / yaconfig-0.6.1.tar.gz

Download URL yaconfig-0.6.1.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1d25c09ceba77e464fae1775ba109293e0bcf389cb6ea050aa619e4843bd8489
BLAKE2b-256 checksum
How to use checksums
4eabac6b10d3712f0e3280ed132f1d58deeeb1f4f51fd055b1034327e6ebf34c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / yaconfig-0.6.1-py2.py3-none-any.whl

Download URL yaconfig-0.6.1-py2.py3-none-any.whl
Size 6.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1e93d231e7306e4c3d48243827d3c71366c756dc81b0a54caec3f06a48502356
BLAKE2b-256 checksum
How to use checksums
75d29b965882b172ff8a1749cffc857d083f15d7101c5cd4ee045fa9997607c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page