{ "info": { "author": "Manuel Pasieka", "author_email": "manuel.pasieka@protonmail.ch", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Configfy\nDecorator library to expose keyword arguments through config files\n\nConfigfy 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.\n\nIt can be used to quick and dirty add new arguments to an function,\nor substitute the complete configuration management for an application.\n\nHostet on [github](https://github.com/mapa17/configfy)\n\n# Installation\nConfigfy is best installed using pip\n\n```bash\n pip install configfy\n```\n\n# Simple example\n\nDefine a function that makes use of keyword arguments, and overwrites the default\nkeyword argument with a config file setting.\n\n```python\nimport configfy\nfrom configfy import configfy as cfy \n\n@cfy\ndef hello(name, another_name='Pedro'):\n \"\"\"Be nice and say hello \n \"\"\"\n print(f'Hello {name}, I am {another_name}!')\n\nhello('Bob')\n```\n\nWith a config.ini containing\n\n```ini\n[global]\nanother_name = 'Suzan Flusan'\n```\n\nproduces\n\n```bash\nHello Bob, I am Suzan Flusan!\n```\n\nNote: Be aware that the library expects the presence of a config file (./configfy.ini) containing at least the empty section [global].\n\n# Advanced Example\nShow how to specify sections to use in config files and how the config file can be changed during runtime, or specified in the decorator.\n\n> From docs/example.py\n```python\nimport configfy\nfrom configfy import configfy as cfy \n\n@cfy\ndef hello(name, another_name='Pedro'):\n \"\"\"Be nice and say hello \n \"\"\"\n print('Hello %s, I am %s!' % (name, another_name))\n\n\n@cfy(section='greetings_section')\ndef greetings(name, language='english'):\n \"\"\"Give a nice greeting ...\n \"\"\"\n if language == 'english':\n print('Hello %s! How are you doing?' % (name))\n elif language == 'spanish':\n print('Hola %s! Que tal?' % (name))\n elif language == 'german':\n print('Hallo %s! Wie gehts?' % (name))\n elif language == 'serbian':\n print('Zdravo %s! Kako si?' % (name))\n else:\n print('!nuqneH %s!' % (name))\n\n\n@cfy(config='yet_another_config.ini')\ndef goodby(msg='Goodby!'):\n print(msg)\n\n\nprint('# Use default configfy.ini file (missing greetings section)...')\nprint('# Current config: %s' % configfy.configfile.config)\nhello('Bob')\ngreetings('Tom')\ngoodby()\n\n\nprint('\\n# Changing config to \"another_config.ini\" ...')\nconfigfy.set_active_config_file('another_config.ini')\nprint('After setting new config file, current config: %s' % configfy.configfile.config)\nhello('Bob')\ngreetings('Tom')\ngoodby()\n\n\nprint('\\n# Specifying kwargs, overwriting config settings...')\nhello('Bob', another_name='Alfredo')\ngreetings('Tom', language='serbian')\ngoodby(msg='That\\'s all Folks!')\n```\n\nProduces\n\n```bash\n# Use default configfy.ini file (missing greetings section)...\n# Current config: OrderedDict([('global', {'another_name': 'Suzan Flusan', 'language': 'spanish'})])\nHello Bob, I am Suzan Flusan!\n# 2018-08-01 17:45:53,834 - configfy - WARNING - Config section greetings_section not found!\nHello Tom! How are you doing?\nGoodby!\n\n# Changing config to \"another_config.ini\" ...\nAfter setting new config file, current config: OrderedDict([('global', {'language': 'spanish', 'msg': 'A goodby message! Ignored'}), ('greetings_section', {'language': 'german'})])\nHello Bob, I am Pedro!\nHallo Tom! Wie gehts?\nGoodby!\n\n# Specifying kwargs, overwriting config settings...\nHello Bob, I am Alfredo!\nZdravo Tom! Kako si?\nThat's all Folks!\n```\n\n# Complete config replacement\nThis is a complete example making use of configfy as a general tool to replace\nthe configuration file for an application. The source code can be found in ./doc\n\n```python\nimport click\nimport configfy\nfrom configfy import configfy as cfy\n\n# Two user functions that get their kwargs from the current config file\n@cfy\ndef user_function1(kw1=23, name1=''):\n print('Calling user_function1(%s, %s) ...' % (kw1, name1))\n\n@cfy\ndef user_function2(kw2=None, name2=''):\n print('Calling user_function2(%s, %s) ...' % (kw2, name2))\n\n\n# Use the excellent click library to handle program arguments\n@click.group()\n@click.version_option(0.1)\n@click.option('-v', '--verbose', count=True)\n@click.option('--config', default='configfy.ini', help='Specify the configfy file to use')\ndef example(verbose, config):\n \"\"\"\n Enabling sub commands\n \"\"\"\n # Load config file\n configfy.set_active_config_file(config)\n\n global config_file\n config_file = config\n\n\n@example.command()\ndef ex1():\n user_function1()\n\n\n@example.command()\ndef ex2():\n user_function2()\n\n\nif __name__ == '__main__':\n example()\n\n```\n\nconfig file:\n```ini\n[global]\n# Pass a number and a list\nkw1 = 1001\nname1 = ['l', 'i', 's', 't']\n\n# Pass a dict and a set\nkw2 = {'d': 42}\n# Note: passing set(1, 2, 3) wont work. It will be passed as a string\nname2 = {1, 2, 3}\n```\n\n## Usage\n```bash\n> python complete_example.py --config complete_example.ini ex1\nCalling user_function1(1001, ['l', 'i', 's', 't']) ...\n\n> python complete_example.py --config complete_example.ini ex2\nCalling user_function2({'d': 42}, {1, 2, 3}) ...\n```\n\n\n\n# Debugging\nDebugging functions augmented with configfy can be tricky because instead of stepping\ndirectly into a user function modified by configfy, the debugger will enter the\nconfigfy library code first.\n\nWhat one can do, is make the debugger \"skip\" the configfy library code.\n\n## pdb\n```python\nimport pdb\nfrom configfy import configfy as cfy \n\n@cfy\ndef fuu(kw_me=42):\n print(kw_me)\n\nif __name__ == '__main__':\n # load pdb, making use of the skip parameter\n pdb.Pdb(skip=['configfy.*']).set_trace()\n fuu()\n```\n\n## pudb\n```python\nimport pudb\nfrom configfy import configfy as cfy\n\n# Prevent pudb from stepping into the decorator library code\npudb._get_debugger(skip=['configfy.*'])\n\n\n@cfy\ndef fuu(kw_me=42):\n print(kw_me)\n\nif __name__ == '__main__':\n pudb.set_trace()\n fuu()\n```\n\n# Overhead\nTry it out yourself! Run\n\n> cd doc \\\n> python overhead.py\n\nI got\n\n```bash\nComparing performance ... this can take a while.\nnative: 11.863 sec\nconfigfy+config 11.953 sec\nconfigfy 12.160 sec\n```\n\n\n# Author\nI happy to receive any feedback or comments on github or privately to manuel.pasieka@protonmail.ch\n\n## Why I wrote this module\nI wrote this library because I often have to write prototypes in a *scientific* settings, in which it is unclear upfront what goals to achieve.\n\nIt 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.\n\nIn 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.\n\n# License\nMIT\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mapa17/configfy", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "configfy", "package_url": "https://pypi.org/project/configfy/", "platform": "", "project_url": "https://pypi.org/project/configfy/", "project_urls": { "Homepage": "https://github.com/mapa17/configfy" }, "release_url": "https://pypi.org/project/configfy/1.0.10/", "requires_dist": null, "requires_python": "", "summary": "Decorator library to expose keyword arguments through config files", "version": "1.0.10" }, "last_serial": 4295693, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "17c204e1cbb9c32fa54bd10ded9d6868", "sha256": "c16c72b2cbbba7472857ecc30e3b25ff25155acd714fa0bd9ed6e3fb945bde21" }, "downloads": -1, "filename": "configfy-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "17c204e1cbb9c32fa54bd10ded9d6868", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8202, "upload_time": "2018-07-06T23:49:10", "url": "https://files.pythonhosted.org/packages/68/9c/6ecb202a9f1832fb4fe570ae72d97691c25819f614e260804e0cbb1a0ae8/configfy-1.0.1-py3-none-any.whl" } ], "1.0.10": [ { "comment_text": "", "digests": { "md5": "5abcb469c9b934e58167ed25b22366f6", "sha256": "7ef281aa0e039c1b6800f8680b8947a706d97dda958aebc552294be2a09f7ea2" }, "downloads": -1, "filename": "configfy-1.0.10-py3-none-any.whl", "has_sig": false, "md5_digest": "5abcb469c9b934e58167ed25b22366f6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7653, "upload_time": "2018-09-21T10:15:56", "url": "https://files.pythonhosted.org/packages/58/2c/d398d5ebfc0bfa9f1878a228b6965b2d443c0a9009ea3dd2992c25525ff2/configfy-1.0.10-py3-none-any.whl" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "928d40638a2e312d5f84dbd567be80c8", "sha256": "cbc5ad7a950155c7d895043228ea6d3f4c693acaf5407f7737e390ed89705c43" }, "downloads": -1, "filename": "configfy-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "928d40638a2e312d5f84dbd567be80c8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5987, "upload_time": "2018-07-06T23:59:11", "url": "https://files.pythonhosted.org/packages/17/ee/15a09c672bf20c80a06c88ae0faf344832648d9821342f36f7566edc93f6/configfy-1.0.2-py3-none-any.whl" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "9d95f039c5a9608d102633fa061fa8b2", "sha256": "b28b6d87b6eb89bfb7b6b8a96e9151b3cff9c351a5aa4495a444e76a6d41685c" }, "downloads": -1, "filename": "configfy-1.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "9d95f039c5a9608d102633fa061fa8b2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5983, "upload_time": "2018-07-07T00:01:19", "url": "https://files.pythonhosted.org/packages/6a/bf/c29151b95078ec212e3c33637dfd1a964721e292131039e0a0549532b70d/configfy-1.0.3-py3-none-any.whl" } ], "1.0.4": [ { "comment_text": "", "digests": { "md5": "512468d783d9dbd04bc7691f2767d13a", "sha256": "d4749f713db3780f32d7ddfd1d8759decbf68e7360f54d8b87f4c0f9228a0036" }, "downloads": -1, "filename": "configfy-1.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "512468d783d9dbd04bc7691f2767d13a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5983, "upload_time": "2018-07-07T00:10:08", "url": "https://files.pythonhosted.org/packages/e8/10/e41cb471d0c68f107501a69015f7da1965bba77a06fb20b506ebb2bd50c7/configfy-1.0.4-py3-none-any.whl" } ], "1.0.5": [ { "comment_text": "", "digests": { "md5": "d92cd7414b416d69cdbac89537fcb4bf", "sha256": "4f816c8df6dbf5120cb17505f39f9866f74a1d77b308a8c406c8be8400146b90" }, "downloads": -1, "filename": "configfy-1.0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "d92cd7414b416d69cdbac89537fcb4bf", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6270, "upload_time": "2018-07-14T16:25:40", "url": "https://files.pythonhosted.org/packages/16/50/fac4a38aaf8b47ebc5a96e6bbd9ee7bc49175c16bdc9f275bf5eee4079fc/configfy-1.0.5-py3-none-any.whl" } ], "1.0.6": [ { "comment_text": "", "digests": { "md5": "db91f8e14340463fe1a6489f1fadda56", "sha256": "c695b68450918618801fdc2e484e3f6eefd1970e350fb6cab9aa4da66ad31a9f" }, "downloads": -1, "filename": "configfy-1.0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "db91f8e14340463fe1a6489f1fadda56", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6457, "upload_time": "2018-07-29T15:20:15", "url": "https://files.pythonhosted.org/packages/94/57/dfbb8b2af98633c8104b0490ab60acbd70a1e96a12811e4613a6243b2378/configfy-1.0.6-py3-none-any.whl" } ], "1.0.7": [ { "comment_text": "", "digests": { "md5": "924b87a3682746ce99b97d1cb83a96b4", "sha256": "70b074b42aaa098004824100fe6e7bf09307026094af6da439f7532d80b1e73e" }, "downloads": -1, "filename": "configfy-1.0.7-py3-none-any.whl", "has_sig": false, "md5_digest": "924b87a3682746ce99b97d1cb83a96b4", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6537, "upload_time": "2018-07-31T10:10:52", "url": "https://files.pythonhosted.org/packages/34/00/88dc5bdb29e76b930b90bc5e01fea53a6282f658d47e2979579bb8e6e722/configfy-1.0.7-py3-none-any.whl" } ], "1.0.8": [ { "comment_text": "", "digests": { "md5": "8d96056557c42d1d4d8ba0d6f395b509", "sha256": "5d297b39f18c23f288c1292e0974a0b82ec4685e6e6ff7365fe1ac4f5a874451" }, "downloads": -1, "filename": "configfy-1.0.8-py3-none-any.whl", "has_sig": false, "md5_digest": "8d96056557c42d1d4d8ba0d6f395b509", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6670, "upload_time": "2018-08-01T14:45:41", "url": "https://files.pythonhosted.org/packages/60/8a/862691ce59f9543f19da651db679838f9d0fc9773ecf0bcb12f2215fef75/configfy-1.0.8-py3-none-any.whl" } ], "1.0.9": [ { "comment_text": "", "digests": { "md5": "f3272ec6d9036d17585d56ced278584b", "sha256": "9ced53e9f9f34d40c9253b3f6d807d2743375a188f7b7351fd9fdafa65ce0837" }, "downloads": -1, "filename": "configfy-1.0.9-py3-none-any.whl", "has_sig": false, "md5_digest": "f3272ec6d9036d17585d56ced278584b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6805, "upload_time": "2018-08-01T15:49:54", "url": "https://files.pythonhosted.org/packages/ee/ad/5d96b3646d44780ad52ae1e9f0c44b72651b148b32ecc92a460b1b89362a/configfy-1.0.9-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5abcb469c9b934e58167ed25b22366f6", "sha256": "7ef281aa0e039c1b6800f8680b8947a706d97dda958aebc552294be2a09f7ea2" }, "downloads": -1, "filename": "configfy-1.0.10-py3-none-any.whl", "has_sig": false, "md5_digest": "5abcb469c9b934e58167ed25b22366f6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7653, "upload_time": "2018-09-21T10:15:56", "url": "https://files.pythonhosted.org/packages/58/2c/d398d5ebfc0bfa9f1878a228b6965b2d443c0a9009ea3dd2992c25525ff2/configfy-1.0.10-py3-none-any.whl" } ] }