Environment to python dictionary parser util
pip install env2dict
About
This small package provides an ability of easy setting/overriding Python variables from environment. It is expected that u will use it to override your configuration data without changing configuration files itself, what is especially useful for containers-oriented applications.
Syntax
To use it, u need to define environment variables matches the pattern: PrefixBodyOperationSuffix where:
- Prefix is any word to determine target variables; for instance,
DDprefix means to use only variables starts withDD; can be empty, what means to select all available variables (not recommended) - Body is the name of the target configuration parameter
- OperationSuffix is the one of next available suffixes (by default, but u can change your defaults):
_NUMBERto convert variable value to integer (environment variables are always strings)_FLOATto convert variable value to float_FLAGto convert variable value tooptional[boolean]at that values:1/yes/Yes/True/trueequaltrue0/no/No/False/falseequalfalseNone/null/NULLequalnull
_LISTmeans to parse variable value to string list_LIST_APPENDmeans to parse variable value to string list and append to existing list instead of override_JSONmeans to parse variable value as json string- no suffix means that no conversion will be performed, so variable value will stay a string
Moreover, u can put nested dicts values using __ separator (or other on your choice) in the environment variable name.
Note also that u can combine these suffixes to perform more complicated transformations.
Examples
- env variable
DD_S_COUNT_NUMBER=10(with prefixDD_conversation) will be converted toS_COUNT=10Python object DD_S_COUNT=10🠚S_COUNT="10"DD_USE_THIS_FLAG=yes🠚USE_THIS=TrueDD_USE_THIS_FLAG=true🠚USE_THIS=TrueDD_USE_THIS_FLAG=no🠚USE_THIS=FalseDD_ALLOWED_HOSTS_LIST_APPEND=127.0.0.1;dev.ocr.com;dev.web.comwill append a list['127.0.0.1', 'dev.ocr.com', 'dev.web.com']toALLOWED_HOSTSvariableDD_READ_ME_JSON={\"a\": 1, \"b\": [1, 2]}will be translated toREAD_ME={'a': 1, 'b': [1, 2]}DD_SOME_DICT__KEY1__KEY2=postgreswill create a dictionarySOME_DICT={'KEY1': {'KEY2': 'postgres'}}if it doesn't exist and will add a field in existing dictionary by aforementioned routeDD_A__B_LIST_APPEND_JSON=[1, 2, 3, [1, 2, \"3\"]]will append[1, 2, 3, [1, 2, "3"]]to the end of valueVfromA={"B": V}
How to use
from env2dict import parse_vars
new_vars = parse_vars(
prefix='DD_',
initial_vars=None,
source=None
)
More info
Please take a look at:
parse_varsfunction docstringtestsdirectory of this package repo.
Metadata
Release files for env2dict 0.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 | Actions |
|---|---|---|---|---|
| env2dict-0.1.0.tar.gz | 6.7 kB | Without provenance | Details for env2dict-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| env2dict-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for env2dict-0.1.0-py3-none-any.whl |
Total release size: 13.6 kB
Release files / env2dict-0.1.0.tar.gz
| Download URL | env2dict-0.1.0.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a113ef92c63f2ce007a1ccbe2076d22586f284da30c8c0479594455b15bc6ff
|
|
BLAKE2b-256 checksum How to use checksums |
e8ca1c6f5be1a69d21bc6bf668eacb6a012973e808423a6d16b23cb22bae699e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.8.17
|
Release files / env2dict-0.1.0-py3-none-any.whl
| Download URL | env2dict-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8f987f2bc1e246805937c92f06441dab937e04960010a62c0f050019f1758c74
|
|
BLAKE2b-256 checksum How to use checksums |
fa78201ce2fca08fe0f15d0520f7fa865782b70f7db4b929a2f45b73b086f30d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.8.17
|
Security for env2dict 0.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.