An easy module for configuration
Project description
AlphaConfig
Introduction
AlphaConfig is easy to read and easy to use, which is designed for configuration.
Installation
You can install AlphaConfig by pip.
pip install AlphaConfig
APIs
init(src_dict: dict=None, path2yaml: os.PathLike=None, path2json: os.PathLike=None, read_only: bool=False, **kwargs)
Info:
Initialize a AlphaConfig instance.
Args:
src_dict (dict): Create an AlphaConfig instance from python builtin's dict, default is None.
path2yaml (os.PathLike): Create an AlphaConfig instance from a yaml file, default is None.
path2json (os.PathLike): Create an AlphaConfig instance from a json file, default is None.
read_only (bool): Set the state of AlphaConfig instance, modification is allowed only if its value is False.
kwargs (key-value pairs): Create attribute-value pairs from key-value pairs.
Example
from alphaconfig import AlphaConfig
test_dict = {
"attr_1": 1,
"attr_2": {
"attr_2_1": [2, 3],
"attr_2_2": "this is attr_2_2",
}
}
configs = AlphaConfig(test_dict, attr_3="value_3")
print(configs)
# * ATTRIBUTES *
# - attr_1: 1
# - attr_2:
# - attr_2_1: [2, 3]
# - attr_2_2: this is attr_2_2
# - attr_3: value_3
is_read_only()
Info:
Allow user to check whether an instance is read only or not.
Returns:
(bool): True if it is read only else False.
cvt2dict()
Info:
Convert an AlphaConfig instance to a python builtin's dict.
Returns:
(dict)
Examples
test_dict = {
"attr_1": 1,
"attr_2": {
"attr_2_1": [2, 3],
"attr_2_2": "this is attr_2_2",
}
}
configs = AlphaConfig(test_dict, attr_3="value_3")
print(configs.cvt2dict())
# {'attr_1': 1, 'attr_2': {'attr_2_1': [2, 3], 'attr_2_2': 'this is attr_2_2'}, 'attr_3': 'value_3'}
cvt_state(read_only: bool=None)
Info:
Convert the readable state according to the given arg.
Args:
read_only (bool): Set the readable state, if no value is given, revert the state.
Returns:
(bool): The final readable state.
keys()
Info:
Get all user-defined attributes. This method act like a python builtin's dict.
Returns:
(dict_keys)
values()
Info:
Get all user-defined values of corresponding keys. This method act like a python builtin's dict.
Returns:
(dict_values)
items()
Info:
Get all user-defined values of corresponding keys. This method act like a python builtin's dict.
Returns:
(dict_items)
iter()
AlphaConfig supports iter
.
Example
test_dict = {
"attr_1": 1,
"attr_2": {
"attr_2_1": [2, 3],
"attr_2_2": "this is attr_2_2",
}
}
config = AlphaConfig(test_dict)
for it in config:
print(it)
# ('attr_1', 1)
# ('attr_2', {'attr_2_1': [2, 3], 'attr_2_2': 'this is attr_2_2'})
copy and deepcopy
AlphaConfig supports copy and deepcopy, just call copy
module.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
alphaconfig-0.0.3.tar.gz
(4.7 kB
view details)
Built Distribution
File details
Details for the file alphaconfig-0.0.3.tar.gz
.
File metadata
- Download URL: alphaconfig-0.0.3.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6ecbd3fe7bcc6a46f2d0e8b268b76ff1b4c967dda4d2c1863060d79047320a4 |
|
MD5 | cde182ee895c1f4a93c51bac354de188 |
|
BLAKE2b-256 | 5599587c21573ed7bc65d4ba17d9e810ebc16bf9a9807c83411e0d0f0b05a5cc |
File details
Details for the file alphaconfig-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: alphaconfig-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2af0e3368e4d8daa46e21a3a0960dfb00d820966c3ccb8ae6c493c07e826edf7 |
|
MD5 | fbd26bf1ce473b0d64c1a58e463093f8 |
|
BLAKE2b-256 | bec6944bdd6e43672855d8498db63acb1c4e2c3ba0a18cea0a22a44a68cfb947 |