EMS-config
This project introduces a unified way of handling config files. The philosophy is having a text-based config file (ini, yml or toml) and then perform parsing and sanity-checking in code afterwards. Moreover, a default layout is encouraged.
You need to provide three paths
- An
app_datadirectory. This is where you should put all your data and where your final config file should go. This is set in an environmental variableAPP_DATA_PATH, which defaults toapp_data. - A path to your final config file. This defaults to
$APP_DATA_PATH/config.iniif your template file is calledconfig.example.ini(see below). That is, it strips.examplefrom the filename of you template file. - A path to the template file. This defaults to
config.example.ini.
Notice that 2 and 3 can both be set in the following parse-method or in environmental variables (CONFIG_PATH and CONFIG_TEMPLATE_PATH)
The assumed layout of you directory would then be something like
project
- app_data/
- config.ini
- app.py
- config.py
- config.example.ini
Where config.py contains the following,
from ems_config import parse_config
config = parse_config()
URL = config["DEFAULT"]["URL"]
and the template config.ini.example contains an example of the configuration,
[DEFAULT]
URL = http://google.com
You can then use the configuration in other python files like this,
from config import URL
print(URL) # do stuff with the URL
Notice, if the config.ini in app_data (or where ever you choose to place it), the template
will be copied to that location.
Helper methods
This library provides a few helper methods found in ems.helpers
# Get the path of p relative to the APP_DATA_DIR
get_from_app_data(p)
## Help to parse from .ini style files
parse_dt_or_none(...)
parse_list_or_none(...)
Customization
If you don't want your template to be named after the above scheme, you can pass another template
path into the parse_config() methods. Likewise, if you want you final config file to be located elsewhere,
you can also provide another path
from ems_config import parse_config
# config_path will default to $APP_DATA_PATH/cfg.ini
config = parse_config(config_template='templates/cfg.example.ini')
config = parse_config(config_template='templates/cfg.ini', config_path='/etc/app.ini')
Metadata
Release files for ems-config 0.0.15
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 |
|---|---|---|---|---|
| ems-config-0.0.15.tar.gz | 4.0 kB | Without provenance | Details for ems-config-0.0.15.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ems_config-0.0.15-py3-none-any.whl | Python 3 | none | any | Details for ems_config-0.0.15-py3-none-any.whl |
Total release size: 8.1 kB
Release files / ems-config-0.0.15.tar.gz
| Download URL | ems-config-0.0.15.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0c8c2e201e91cbd6364628cbf6fc95a34cf7ba5b682bb112440f51124102d3cf
|
|
BLAKE2b-256 checksum How to use checksums |
5a8a662c0f6ca3675f1cf5ba2e4adae50f094e8980ba2f1e08b64bdd40659c93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9
|
Release files / ems_config-0.0.15-py3-none-any.whl
| Download URL | ems_config-0.0.15-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fed2b689ea8d70af1069693b537b6a64261316ee8dac78dd93d7dedfe870c4cf
|
|
BLAKE2b-256 checksum How to use checksums |
5753ef4abe076d830d6dd9094ddf4b2bfdff0d4df2bacaa9757607aa820fbf67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9
|
Security for ems-config 0.0.15
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.