Skip to main content

Python package to assist configuration

Project description

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

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

yaconfig-0.6.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

yaconfig-0.6.1-py2.py3-none-any.whl (6.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file yaconfig-0.6.1.tar.gz.

File metadata

  • Download URL: yaconfig-0.6.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for yaconfig-0.6.1.tar.gz
Algorithm Hash digest
SHA256 1d25c09ceba77e464fae1775ba109293e0bcf389cb6ea050aa619e4843bd8489
MD5 13a6ddacf423ad03e42fefc3a57107af
BLAKE2b-256 4eabac6b10d3712f0e3280ed132f1d58deeeb1f4f51fd055b1034327e6ebf34c

See more details on using hashes here.

File details

Details for the file yaconfig-0.6.1-py2.py3-none-any.whl.

File metadata

  • Download URL: yaconfig-0.6.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for yaconfig-0.6.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1e93d231e7306e4c3d48243827d3c71366c756dc81b0a54caec3f06a48502356
MD5 5bb101e7f516790ee2df17b85fd85830
BLAKE2b-256 75d29b965882b172ff8a1749cffc857d083f15d7101c5cd4ee045fa9997607c2

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