yaconfig
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 inconfig["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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| yaconfig-0.6.1.tar.gz | 7.0 kB | Without provenance | Details for yaconfig-0.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| yaconfig-0.6.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for yaconfig-0.6.1-py2.py3-none-any.whl |
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
|
Security for yaconfig 0.6.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.