anenvconf
A python3 module for defining a config schema and importing it from environment variables.
Install
python3 -m pip install anenvconf
Usage
Import the modules key classes, define the config schema and create a Config object with the schema.
from anenvconf import Config, ConfigValueType
config_schema = {
'jsonvar1': {
'type': ConfigValueType.JSON,
'required_key': 'important_key'
},
'stringvar1': {},
'stringvar2': {
'default': "Default value in case setting this variable is not mandatory"
},
'boolvar1': {
'type': ConfigValueType.BOOL,
'default': True
}
}
config = None
try:
config = Config(config_schema)
except anenvconf.exceptions.InvalidValueException as e:
print("Got an invalid value: ", e.text)
except anenvconf.exceptions.EnvironmentVarMissingException as e:
print("A required environment variable is missing: ", e.text)
except anenvconf.exceptions.RequiredVarMissingException as e:
print("A required value inside a variable is missing: ", e.text)
if config is not None:
print(config.get_value("stringvar2"))
Schema
The schema is given as a dict, where the keys are the environment variables to read, and each of their values is an another dict that defines details about how to handle that variable. The dict that defines the handling can have the following keys:
type is the data type of the variable value, defined as ConfigValueType. Supported types are str (default),
bool, intand json.
default is the default value of the variable. If defaultis not set, the environment variable is treated
as mandatory. If you want to have optional variables, you can for example set default to None.
required_key defines a key that is required in the keys of a json type of value. If the key is not found, an exception is raised.
Example:
example_config_schema = {
# Use "type" to define ConfigValueType, string is assumed by default.
'env_variable_name1': {
'type': ConfigValueType.JSON
},
# Default data type is string
'env_variable_name2': {},
# If default value exists, value from environment variable is not required.
# Otherwise the key-value pair is expected to be found in the env variables.
'env_variable_name3': {
'type': ConfigValueType.JSON,
'default': '{}'
}
}
Metadata
Release files for anenvconf 1.0.2
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 |
|---|---|---|---|---|
| anenvconf-1.0.2.tar.gz | 4.1 kB | Without provenance | Details for anenvconf-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| anenvconf-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for anenvconf-1.0.2-py3-none-any.whl |
Total release size: 8.6 kB
Release files / anenvconf-1.0.2.tar.gz
| Download URL | anenvconf-1.0.2.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09dfc6fa9c1b2ad41d4d1a46a1e1c48cad64cf1a62184cb7f5b0e49b822f24a6
|
|
BLAKE2b-256 checksum How to use checksums |
ca27aca3945fb18f48d2a13cb7256b311e9ea8169e395de59b30360d9c600f88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
|
Release files / anenvconf-1.0.2-py3-none-any.whl
| Download URL | anenvconf-1.0.2-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da9dd79989b8b78416de74a813f3d2b05b628ff68f9f9cf08bc9904ff4c9456b
|
|
BLAKE2b-256 checksum How to use checksums |
6da71ccf48fb21699b023da3d2154fe4bcea17ccc534e6bece417726c7fef644
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
|
Security for anenvconf 1.0.2
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.