Simple out-of-box configs
Project description
cfgmgr
Simple out of the box configurations for python projects
Basic usage
import cfgmgr
cfgmgr.make_config(env_prefix="CFG_", file_path="config.json", find_file=True)
some_val = cfgmgr.getkey('key')
cfgmgr.setkey('key', 'new_val')
config = cfgmgr.get() # the global Config object itself
make_config
- Initializes a global
Configas per args specified - Pass in
env_prefixto read values from environment variablesenv_prefixwill be prefixed to the keys before reading the environment variable- Ex.
env_prefix="CFG_"will effectively translatecfgmgr.getkey('foo')toos.getenv('CFG_foo')
- Values are resolved dynamically, so
cfgmgr.getkeywill respect environment variables set viaos.environ(Useful in test cases) file_pathattempts to resolve the extension and defers to the corresponding loader- JSON and env are always supported. TOML is supported on Python 3.11+ (
tomllib). YAML and dotenv are supported when their packages are installed —pip install cfg-mgr[yaml]/cfg-mgr[dotenv]. - Custom Loaders can be implemented and registered via a decorator
cfgmgr.fileloaders.register('.extension')
- JSON and env are always supported. TOML is supported on Python 3.11+ (
find_file, ifTrue, will crawl upwards fromcwduntil it finds a match forfile_pathinclude_key, if given, enables config includes: a config file may name another file under that key to be pulled in as a base. The including file overrides the included one; nested mappings are deep-merged. Include chains are followed recursively and cycles raiseIncludeCycleError.
getkey and setkey
- Getter and setter for individual keys on the global default
Configobject getkey(key, default=None)returns the resolved value, ordefaultif absentsetkey(key, value)sets an override (highest priority)- Both
raise AttributeErrorifmake_confighas not been called prior to the call
get
- Returns the global default
Configobject itself (aMutableMapping), orNoneifmake_confighas not been called - Use it for mapping-style access:
cfgmgr.get()['key'],'key' in cfgmgr.get(), iteration, etc.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cfg_mgr-0.3.0.tar.gz.
File metadata
- Download URL: cfg_mgr-0.3.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4379d1d0f4e0690087a5a7dbf48c28b14c6cb4bae40d05d2a06aca20471787c3
|
|
| MD5 |
91df6c9ca31885901a954799458aabc4
|
|
| BLAKE2b-256 |
0ff368cffc750c6d9c8b0d7435fd8cd73efbf5d4b396202aa49ff086a01e4254
|
Provenance
The following attestation bundles were made for cfg_mgr-0.3.0.tar.gz:
Publisher:
release.yml on raghavj98/cfgmgr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cfg_mgr-0.3.0.tar.gz -
Subject digest:
4379d1d0f4e0690087a5a7dbf48c28b14c6cb4bae40d05d2a06aca20471787c3 - Sigstore transparency entry: 1563775104
- Sigstore integration time:
-
Permalink:
raghavj98/cfgmgr@8e880bc00ef51d2edeef87dd85e284ce0d6c6380 -
Branch / Tag:
refs/tags/rel-v0.3 - Owner: https://github.com/raghavj98
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8e880bc00ef51d2edeef87dd85e284ce0d6c6380 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cfg_mgr-0.3.0-py3-none-any.whl.
File metadata
- Download URL: cfg_mgr-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12416bd5ddf9369dcaff777905e793f95e77fd56753666b8f68d057e054f5c66
|
|
| MD5 |
6c23d295ebbb2ccce2ea0eb47d39d5b1
|
|
| BLAKE2b-256 |
b2339c4610678503f5a63ddbdd0ee0a1f9374f39bc0442597df1a10d4f4c58ad
|
Provenance
The following attestation bundles were made for cfg_mgr-0.3.0-py3-none-any.whl:
Publisher:
release.yml on raghavj98/cfgmgr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cfg_mgr-0.3.0-py3-none-any.whl -
Subject digest:
12416bd5ddf9369dcaff777905e793f95e77fd56753666b8f68d057e054f5c66 - Sigstore transparency entry: 1563775125
- Sigstore integration time:
-
Permalink:
raghavj98/cfgmgr@8e880bc00ef51d2edeef87dd85e284ce0d6c6380 -
Branch / Tag:
refs/tags/rel-v0.3 - Owner: https://github.com/raghavj98
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8e880bc00ef51d2edeef87dd85e284ce0d6c6380 -
Trigger Event:
push
-
Statement type: