Skip to main content

A simple config reader based on python Config Parser.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ini-config-reader-0.0.3.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file ini-config-reader-0.0.3.tar.gz.

File metadata

  • Download URL: ini-config-reader-0.0.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for ini-config-reader-0.0.3.tar.gz
Algorithm Hash digest
SHA256 311e4e9c945c9f5607897f9d0fb80f3f19279adaccc37a26ac1f7c542b029f61
MD5 a38666e982e47d3cd8259652925c88cd
BLAKE2b-256 65a419d00efa0dd0b47a0355dba5a0d6ad1e9defaccfdcdac79c7220ae90ff8b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page