Skip to main content

This is a simple project to read python configurations from INI files. Has the following features:

  • It uses the Singleton pattern to configure the reader only once and used it across an application.

  • Reloads the configurations when the configuration file is changed.

  • Read OS variables as Strings, e.g., ‘%(LANG)s’

  • The configurations are automatically converted to a python data type

  • Collect a configuration section as a dictionary

The available data types are: - Strings, surrounded by ‘’ or “” - Integers - Floats - Lists, [1,2,3] - Dictionaries, {‘test’: {‘is_dict’: True}}

Installing

To use the config_reader simple install using pip

$ pip install ini-config-reader

Requirements

Python3 tested for versions 3.5, 3.6 and 3.7

Usage

The conf_reader has three class variables, INI_FILE, RELOAD and DICT_CACHE.

Variable

Description

INI_FILE

Path to the file that contains the configurations

RELOAD

Set if the INI file should be reloaded when changes are detected

DICT_CACHE

When collecting the section as dictionary store it in a dict to avoid processing the reading

Regular usage

Since the config_reader implements the singleton pattern the user only needs to configure the INI_File once. Then the get method and get_section_dict can be used as static methods.

from conf_reader.reader import ConfReader

ConfReader('/etc/configuration/my_config.ini')
ConfReader.get('Section_1', 'configuration_1')  # Can be used in different modules

Decorator

The config_reader uses a decorator to inject configuration in functions. To use it the INI_FILE must be already configured and a config variable must exist in the function’s signature.

from conf_reader.reader import ConfReader, read_conf

@read_conf("SECTION_1", 'config_2')
def read_with_arguments(*args, config, **kwargs):
    pass

ConfReader('/etc/configuration/my_config.ini')
read_with_arguments()

License

This project is licensed under the MIT License - see the LICENSE.txt file for details

Release files for ini-config-reader 0.0.3

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

Source distribution (sdist)

Source distribution for ini-config-reader 0.0.3
File Size Uploaded
ini-config-reader-0.0.3.tar.gz 4.5 kB Details

Release files / ini-config-reader-0.0.3.tar.gz

Download URL ini-config-reader-0.0.3.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
311e4e9c945c9f5607897f9d0fb80f3f19279adaccc37a26ac1f7c542b029f61
BLAKE2b-256 checksum
How to use checksums
65a419d00efa0dd0b47a0355dba5a0d6ad1e9defaccfdcdac79c7220ae90ff8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.20.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.0.3 This release

1 release file

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