gen3config
Handle YAML configurations with a given default/expected configuration. Library will overlay a provided configration over the default and ignore unknown values.
Quickstart
Example config-default.yaml for your application:
---
SOME_VALUE: 'default'
EXAMPLE:
nested:
key: 'value'
is_boolean: true
Example config.py in your application:
from gen3config import Config
class AppConfig(Config):
def __init__(self, *args, **kwargs):
super(AppConfig, self).__init__(*args, **kwargs)
def post_process(self):
# do custom stuff here after parsing config
pass
default_cfg_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "config-default.yaml"
)
config = AppConfig(default_cfg_path)
Now we want to get a specific configuration.
Example file ~/path/to/app-config.yaml:
SOME_VALUE: 'app-specific configuration'
EXAMPLE:
nested:
is_boolean: true
Example initialization function in your application:
from app.config import config
config.load('~/path/to/app-config.yaml')
Then from other files:
from app.config import config
print(config["SOME_VALUE"]) # 'app-specific configuration'
print(config["EXAMPLE"]["nested"]["key"]) # 'value'
NOTE:
config["EXAMPLE"]["nested"]["key"]does not exist in the provided configuration, but it does exist in the default configuration. Therefore, the default value,'value'is retrieved.
Details:
- Create a
config-default.yamlandconfig.pyin the top-level folder your app - Inside
config-default.yamladd keys and reasonable default values - Inside
config.py, create a class that inherits from this Config class- See above example
- Add a final line to your
config.pythat instantiates your custom class:- Ensure that you provide the default config path
- If placed in same directory as
config.pyyou can use something like:default_cfg_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), "config-default.yaml" ) config = FenceConfig(default_cfg_path)
- If placed in same directory as
- Ensure that you provide the default config path
- Import your instaniated object whenever you need to get configuration
- Example:
from fence.config import config
- Example:
- Load in application configuration during init of your app
- Example:
config.load('path/to/fence-config.yaml')
- Example:
- Now you can safely access anything that was in your
config-default.yamlfrom this object as if it were a dictionary- Example:
storage_creds = config["STORAGE_CREDENTIALS"] - Example:
if config["SOME_BOOLEAN"]: ... - Example:
nested_value = config["TOP_LEVEL"]["nested"]
- Example:
- And of course you can import that into any file you want and will have access to
keys/values
- Example:
from fence.config import config
- Example:
Metadata
Release files for gen3config 2.1.0
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 | |
|---|---|---|---|---|
| gen3config-2.1.0.tar.gz | 9.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gen3config-2.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.8 kB
Release files / gen3config-2.1.0.tar.gz
| Download URL | gen3config-2.1.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef31d679b841ca30cd3c285f720b1701024bb27911d327023d9fb6aa559bdef3
|
|
BLAKE2b-256 checksum How to use checksums |
3e37d082d7288326cfe93062d71e1712977a86b13c929d35fa0ce07f3c79677c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.13.11 Linux/6.11.0-1018-azure
|
Release files / gen3config-2.1.0-py3-none-any.whl
| Download URL | gen3config-2.1.0-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7cb088127eb9598ec954c10e083f50d19f6d7360780f4bbf3344443ce83a27e0
|
|
BLAKE2b-256 checksum How to use checksums |
36ba139930a1daad7d29f64a6e55810675f06ee32573c7ae23d3cec99371d02d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.13.11 Linux/6.11.0-1018-azure
|
Security for gen3config 2.1.0
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.