paraparser — parameters parser
Parameters is design for large program with massive parameters. It supports integer, float, bool, string and enumerate(enum) types. Array is supported for bool, integer and float. For enum type, customized value can be set as well. Data type is protected. And load/dump of parameters/config is available.
Get instance
You can get an emptry instance, or load from dict/filename/filehandler
params = paraparser.Parameters()
params = paraparser.Parameters(paramters_dict)
params = paraparser.Parameters(parameter_json)
Load config/parameters
After the parameter instance is generated, you can load from a dict/file as well.
params.LOAD_CONFIG(config_file)
params.LOAD_PARAMETERS(parameters_file)
You can check parameters.json.sample & config.json.sample for details of parameters/config.
update/remove key
Key can be updated/removed, val can be set/reset
>>> params.UPDATE_KEY('test_key', 'int', default=0)
>>> params
{"test_key": 0}
>>> params.test_key = 1
>>> params
{"test_key": 1}
>>> params.test_key
1
>>> params.REMOVE_KEY('test_key')
>>> params.RESET_KEY('test_key')
>>> params
{"test_key": 0}
Special Types
Array
An integer/float/bool array could be initiate with
>>> params.UPDATE_KEY('test_key', 'int', isArray=True, length=10, default=0)
>>> params
{"test_key": "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"}
>>> params.UPDATE_KEY('test_key', 'float', isArray=True, length=6, default=0)
>>> params
{"test_key": "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]"}
Enumerate
We highly improved enum type
>>> params.UPDATE_KEY('test_key', 'enum', enumItems=['x1', 'x2', 'x3'], default='x1')
>>> params
{
"test_key": "x1"
}
>>> params.test_key
key test_key: x1
enums: ['x1', 'x2', 'x3']
You can customize enuemrate enumerate values with enumVals, which is really useful when cooperating with old programs.
>>> params.UPDATE_KEY('test_key', 'enum', enumItems=['x1', 'x2', 'x3'], enumVals=['-1', '2', '5'], default='x1')
>>> params
{
"test_key": "x1"
}
>>> print(params.DUMP_OUTPUT())
test_key = -1
Type Protection
Type is protected within paraparser, e.g.
>>> params.UPDATE_KEY('test_key', 'enum', enumItems=['x1', 'x2', 'x3'], enumVals=['-1', '2', '5'], default='x1')
>>> params
{
"test_key": "x1"
}
>>> params.test_key = 'x22'
AssertionError: Parameters Errror: key "test_key" is a enum, items: ['x1', 'x2', 'x3']
And the same for other types.
Output
A beautiful output is available with the instance or use the print function
>>> print(params)
{
"string": "STRINGSING",
"int": 1,
"float": 1.1,
"enum": "1",
"floatArray": [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ],
"runType": "geometry_converge",
"ialgo": "method1"
}
You could also dump the config with DUMP_CONFIG(), or dump the parameters with DUMP_PARAMETERS() to standard output or to a file/handler
>>> params.DUMP_CONFIG()
{'test_key': {'key': 'test_key', 'type': 'float', 'enumItems': None, 'enumVals': None, 'isArray': True, 'length': 6, 'default': 0.0, 'comments': '', 'reference': ''}}
>>> params.DUMP_PARAMETERS()
{'__keys_config': {'test_key': {'key': 'test_key', 'type': 'float', 'enumItems': None, 'enumVals': None, 'isArray': True, 'length': 6, 'default': 0.0, 'comments': '', 'reference': ''}}, '__keys_values': {'test_key': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}}
>>> params.DUMP_CONFIG('config.json')
>>> params.DUMP_PARAMETERS('parameters.json')
Have Fun!
Metadata
Release files for paraparser 1.0.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 |
|---|---|---|---|---|
| paraparser-1.0.0.tar.gz | 8.1 kB | Without provenance | Details for paraparser-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| paraparser-1.0.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for paraparser-1.0.0-py2.py3-none-any.whl |
Total release size: 17.4 kB
Release files / paraparser-1.0.0.tar.gz
| Download URL | paraparser-1.0.0.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
312150a84c0b84fdfe1e6e549c43ac08b1bf6154e70b038db1891289997175a1
|
|
BLAKE2b-256 checksum How to use checksums |
c05fac1af25214d18100380e9df48c95596180bece36ee6c70dc6b4074f715de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.9.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.7
|
Release files / paraparser-1.0.0-py2.py3-none-any.whl
| Download URL | paraparser-1.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
26ba71fba85819b4b64eb9aeb4b3c6277e1ab04d7eba7e51691fd80ed5574f33
|
|
BLAKE2b-256 checksum How to use checksums |
e7639c9b86a482c5637aecbb46c46ce093a1e226b1f96246446bd6e4e90bb61b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.9.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.7
|
Security for paraparser 1.0.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.