Skip to main content

Build Status Codecov GitHub

Python module wrapper around ConfigParser to ensure strict operation when working with configuration (.ini) files.

Example Usage

Assume a configuration file, config.ini, with the following content:

[General]
api_key = api-private-key
conversion_factor = 123.456
print_results = False

Config parser can be used to ensure the expected values appear in the file, extra values are ignored with default values used as substitutes where entries are missing.

from configchecker import ConfigChecker

config = ConfigChecker()

# Set the configuration values which are to be used.
# set_expectations(SectionName,SectionOption,DataType,DefaultValue)
config.set_expectation('General','api_key',str,'api-private-key')
config.set_expectation('General','retries',int,5)
config.set_expectation('General','conversion_factor',float,3.14)
config.set_expectation('General','print_results',bool,True)

# Try to load a configuration (.ini) file.
# Any previously set expectation which exists in the file has its value updated.
# Any value which doesn't exist in the file has its default value applied.
# Any configuration value in the file which isn't an expectation is ignored.
# This should be called before a file is written, or configuration value set or get
config.set_configuration_file('config.ini')

# Get the value of a configuration variable
printResults = config.get_value("General','print_results')

# Set the value of a configuration variable
config.set_value('General','api_key','123-23423csdfs3-2342-234')

# Write a configuration (.ini) file.
# This operation creates a new file with all the previously set expectations
# If a value hasn't been added for the option, then the default value is used.
config.write_configuation_file('config.ini')

The resulting (new) configuration file look as follows:

[General]
api_key = 123-23423csdfs3-2342-234
retries = 5
conversion_factor = 123.456
print_results = False

Notice the option retries has been added with the default value based on the expectation, and the api_key has been updated. The values of conversion_factor and print_results remained unchanged, as they existed in the original configuration file.

Metadata

Release files for config-checker 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for config-checker 0.0.1
File Size Uploaded
config-checker-0.0.1.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for config-checker 0.0.1
File Interpreter ABI Platform
config_checker-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.5 kB

Release files / config-checker-0.0.1.tar.gz

Download URL config-checker-0.0.1.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3713681b9173f291b57378833173ca3a11cf0d99c199750530c4c8465d59a22b
BLAKE2b-256 checksum
How to use checksums
b05d5b3019985016fb737571246a023e467039aaae5ffe5cc28071125f863f5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / config_checker-0.0.1-py3-none-any.whl

Download URL config_checker-0.0.1-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f1237bdd69fb7222e94ebd8037c042ef72f0c52e7a4e1a5299ea2b4f70e7082
BLAKE2b-256 checksum
How to use checksums
f94ed24270c86678b4f0348c43a151c0842a8f9114f4c8e4505f3b65183e0079
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page