Skip to main content

Small package to easily parse an .ini file.

Project description

configini

Small package to easily parse an .ini file.

Read values

config.ini

[chapter]
key=hello world

Import the configini module into your config.py file. Then read the config.ini file, and fetch the values from the configini module.

config.py:

import configini

# Read the config.ini file.
configini.read('config.ini')

class Config:
    # Set value1 to [chapter] => key
    value = configini.get('chapter', 'key')

Then you can use your config variables like this:

example.py:

# Import the config file
from config import Config

# Do whatever you want with it.
some_variable = Config.value1

Cast data types

To cast values to different data types. you can set the parameter date_type

config.ini:

[chapter]
number=2
decimal=6.2
boolean=true
list=["A", "B", "C"]

config.py:

import configini

class Config:
    integer_value = configini.get('chapter', 'key', data_type=int)
    float_value = configini.get('chapter', 'key', data_type=float)
    boolean_value = configini.get('chapter', 'key', data_type=bool)
    list_value = configini.get('chapter', 'key', data_type=list)

Note: If data_type is set to bool, only empty values, '0' and 'false' will be cast to False.
Note: Only use double quote for strings inside list, the json.loads() method is used for parsing to list.

default values

Default values will be used when the value inside the configurations file is empty. You can change the default value by passing the default parameter.

import configini

class Config:
    value = configini.get('chapter', 'key', default='Hello world')

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

configini-0.3.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

configini-0.3-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

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