Plug-n-Play ConfigParser for extensible use cases.
Project description
ParserConfig
ParserConfig initializes ConfigParser in fewer lines of code.
Installation
Requires Python 3.7+:
python -m pip install parserconfig
Usage
To follow along, create a settings.ini file in your home directory with the following content:
[tutorial]
username = my_username
password = my_password
bearer_token = my_bearer_token
The configuration file can be read using the following code:
from pathlib import Path
from parserconfig import ParserConfig
configuration_file = Path.home().joinpath('settings.ini')
settings = ParserConfig(configuration_file=configuration_file)
The credentials helper method returns a dictionary containing key/value pairs. This can be leveraged in several ways:
credentials = settings.credentials('username', 'password', section='tutorial')
print(f'{credentials = }. Kwargs unpacking is supported via **credentials')
username, password = credentials.values()
print(f'{username = }, {password = }')
The pattern for querying a single value varies slightly:
bearer_token = settings.credentials('bearer_token', section='tutorial')
print(f'{bearer_token = }. Single value also supports kwargs unpacking via **bearer_token')
bearer = bearer_token.get('bearer_token')
print(f'{bearer = }')
token, *_ = bearer_token.values()
print(f'{token = }')
Access to ConfigParser is provided via configuration_file_parser, and can be used to enable ExtendedInterpolation:
from configparser import ConfigParser, ExtendedInterpolation
settings.configuration_file_parser = ConfigParser(interpolation=ExtendedInterpolation())
settings.load_configuration_file()
Advanced Usage
- management_api_tools uses parserconfig to insert data into pytest during test execution.
- offprem creates subclasses of parserconfig.
Local Development and Testing
Development
Development and testing should be done in a virtual environment.
$ git clone https://github.com/Fauxsys/parserconfig.git
$ cd parserconfig
$ python -m venv venv --prompt parserconfig
$ source venv/bin/activate
(parserconfig) $ python -m pip install -U pip
Install parserconfig locally.
(parserconfig) $ python -m pip install -e ".[test]"
Testing
You can test any changes locally with pytest.
(parserconfig) $ python -m pytest --cov=parserconfig
You can also test parserconfig as an installed package.
(parserconfig) $ python -m tox
Building a wheel
(parserconfig) $ python -m pip install build
(parserconfig) $ python -m build --wheel
There should now be a wheel in the dist directory.
(parserconfig) $ ls -1 dist
parserconfig-1.0.0-py3-none-any.whl
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 Distributions
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 parserconfig-1.0.0-py3-none-any.whl.
File metadata
- Download URL: parserconfig-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c69df7d809bf3ad0246914c0b7f5ad0451b24a482c3145dbf8f012941ca67a7
|
|
| MD5 |
969a591280c6ca4338f817b6e24cc024
|
|
| BLAKE2b-256 |
373ed9d1bb3330802590c6a7a66e63d49eabffa79136d8ba5af2d16c3ece2ffe
|