python util for cfg (configurations)
Project description
pyutil-cfg
python utilility for configurations.
This package helps parsing .toml configurations and json-like configurations in .ini.
Usage
import pyutil_cfg as cfg
logger, config = cfg.init(name, filename)
File Formats
.toml
For the .toml files, the format follows TOML specification.
You can check production.tmpl.toml for more details.
.ini
For the .ini files, you can check production.tmpl.ini for more details.
Assume that you have the following development.ini:
[demo]
VAR_INT = 1
VAR_BOOL = true
VAR_DICT = {"A": 1, "B": "a"}
VAR_LIST = [
{"A": 2, "B": "b"},
{"A": 3, "B": "c"},
{"A": 4, "B": "d"}]
Then with the following code:
import pyutil_cfg as cfg
logger, config = cfg.init('demo', 'development.ini')
logger is a logger with name = 'demo'
config ia as follow:
config = {
"VAR_INT": 1,
"VAR_BOOL": true,
"VAR_DICT": {"A": 1, "B": "a"},
"VAR_LIST": [
{"A": 2, "B": "b"},
{"A": 3, "B": "c"},
{"A": 4, "B": "d"}
],
}
Advanced Usage
Separated log configuration filename
import pyutil_cfg as cfg
logger, config = cfg.init(name, filename, log_name, log_filename)
Additional customized config parameters (specified as dict)
import pyutil_cfg as cfg
extra_params = {}
logger, config = cfg.init(name, filename, extra_params=extra_params)
Ok if extra parameters are already in the configuration file (default: True)
It is usual that we would like to temporarily change the configuration settings through command-line variables.
Because usually we still want to continue the process even if the extra parmeters
are accidentally in the configuration file.
Only warning logs if this parameter is set as False and some extra parameters are already in configuration file.
import pyutil_cfg as cfg
logger, config = cfg.init(name, filename, is_extra_params_in_file_ok=True)
Skip extra parameters if they are already in the configuration file.
Skip extram parameters if they are already in the configuration file.
import pyutil_cfg as cfg
logger, config = cfg.init(name, filename, is_skip_extra_params_in_file=True)
Show configuration before returning.
Setup the log-level to show the computed configurations before return. None as no-show.
Do not show the configuration before return.
import pyutil_cfg as cfg
logger, config = cfg.init(name, filename)
Show the configruration if the logger is set to logging.DEBUG
import pyutil_cfg as cfg
logger, config = cfg.init(name, filename, show_config=logging.DEBUG)
Show the configuration if the logger is set to logging.INFO or logging.DEBUG.
import pyutil_cfg as cfg
logger, config = cfg.init(name, filename, show_config=logging.INFO)
Misc
- Reason not including .json: not a good file format for config.
- Reason not including .yaml: not the standard library.
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 pyutil_cfg-0.1.0.tar.gz.
File metadata
- Download URL: pyutil_cfg-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70820fd8fd08e0e7e6afbc434444cd1644891f25012b9202031f725c320414bc
|
|
| MD5 |
660c40daa2dbb4b2f1fed35ec720dcb5
|
|
| BLAKE2b-256 |
2568bfd3f4606db1ca3ebc95900c79d005b8b656b017c00d13fc2130598ac799
|
File details
Details for the file pyutil_cfg-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyutil_cfg-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df4e2ab086ba9a02dc3d72fc7b63291e437ddf7203dd5e34a056cb3c499878c3
|
|
| MD5 |
ee41bb1baa3437dd2885eaebf4a98269
|
|
| BLAKE2b-256 |
778577cfff3dca6d526850c43474c8ccd8a85db6c79bac556385ef25dd57c64e
|