Skip to main content

Decorator library to expose keyword arguments through config files

Project description


Decorator library to expose keyword arguments through config files

Configfy is a prototyping library that enables fast exposure of function parameters to the user in order modify program behavior without having to handle argument parsing or control the flow of config options through your program. It is implemented as a decorator library that makes use of the python configparser module.

Hostet on github


Configfy is best installed using pip

    pip install configfy


Define a function that makes use of keyword arguments, and overwrites the default keyword argument with a config file setting.

import configfy
from configfy import configfy as cfy 

def hello(name, another_name='Pedro'):
    """Be nice and say hello 
    print(f'Hello {name}, I am {another_name}!')


With a config.ini containing

another_name = Suzan Flusan


Hello Bob, I am Suzan Flusan!

Note: Be aware that the library expects the presence of a config file (./configfy.ini) containing at least the empty section [global].

More Examples

Show how to specify sections to use in config files and how the config file can be changed during runtime, or specified in the decorator.

From docs/

import configfy
from configfy import configfy as cfy 
from pudb import set_trace as st

def hello(name, another_name='Pedro'):
    """Be nice and say hello 
    print(f'Hello {name}, I am {another_name}!')

def greetings(name, language='english'):
    """Give a nice greeting ...
    if language == 'english':
        print(f'Hello {name}! How are you doing?')
    elif language == 'spanish':
        print(f'Hola {name}! Que tal?')
    elif language == 'german':
        print(f'Hallo {name}! Wie gehts?')
    elif language == 'serbian':
        print(f'Zdravo {name}! Kako si?')
        print(f'!nuqneH {name}!')

def goodby(msg='Goodby!'):

print('# Use default configfy.ini file (missing greetings section)...')

print('\n# Changing config to "another_config.ini" ...')

print('\n# Specifying kwargs, overwriting config settings...')
hello('Bob', another_name='Alfredo')
greetings('Tom', language='serbian')
goodby(msg='That\'s all Folks!')


# Use default config.ini file (missing greetings section)...
Hello Bob, I am Suzan Flusan!
WARNING:root:Config section greetings_section not found!
Hello Tom! How are you doing?

# Changing config to "another_config.ini" ...
Hello Bob, I am Pedro!
Hallo Tom! Wie gehts?

# Specifying kwargs, overwriting config settings...
Hello Bob, I am Alfredo!
Zdravo Tom! Kako si?
Thats all Folks!


Try it out yourself! Run

python doc/

I got

Comparing performance ... this can take a while.
native: 11.863 sec
configfy+config 11.953 sec
configfy 12.160 sec


I happy to receive any feedback or comments on github or privatly to


I wrote this library because I often have to write prototypes in a scientific settings, in which it is unclear upfront what goals to achieve.

It often happened to me that I had to introduce additional parameters and options to functions deep down in the application flow, in order to make its behavior alterable by the user. One can do this by either some global config file, or parse program arguments and pass them through multiple layers to the desired functions.

In order to make those steps easier and speed things up, I wrote this library which enables one to post-hoc add keyword arguments to any function in the codebase, and expose them to the user via a simple config file.

Project details

Download files

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

Files for configfy, version 1.0.6
Filename, size File type Python version Upload date Hashes
Filename, size configfy-1.0.6-py3-none-any.whl (6.5 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page