Skip to main content

Decorator library to expose keyword arguments through config files

Project description


Decorator library to expose keyword arguments through config files by

Hostet at github

  • [Example](##Simple Example) Look at a simple example
  • Performance overhead Whats the additional computational cost?
  • What for? What is it good for?

Simple Example

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'):
    """Some print statement 
    print(f'Hello {name}, I am {another_name}!')


With a config.ini containing

another_name = Suzan Flusan


Hello Bob, I am Suzan Flusan!

Complex Example

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'):
    """Some print statement 
    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 config.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 wrote this library because I often have to write prototypes in a scientific settings, in which it is unclear upfront which goals to achieve.

I therefore often have to introduce additional parameters and options to some function deep down in the application flow, and in order to make its behavior alterable by the user, one has to either have some global config file, or pass arguments from the user input to that part of the execution.

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.2
Filename, size File type Python version Upload date Hashes
Filename, size configfy-1.0.2-py3-none-any.whl (6.0 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