{ "info": { "author": "krasch", "author_email": "code@krasch.io", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Software Development" ], "description": "quickargs\n---------\n\nTakes a YAML config file and builds a parser for command line arguments\naround it. This allows you to easily override default settings by\npassing command line arguments to your program. Supports nested\narguments and auto-enforces parameter types.\n\nThis config file...\n^^^^^^^^^^^^^^^^^^^\n\n.. code:: yaml\n\n input_dir: data\n logging:\n file: output.log\n level: 4\n\n... together with this main.py ...\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code:: python\n\n import yaml\n import quickargs\n\n with open(\"config.yaml\") as f:\n config = yaml.load(f, Loader=quickargs.YAMLArgsLoader)\n\n... will give you this command line interface\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n::\n\n usage: main.py [-h] [--input_dir INPUT_DIR] [--logging.file LOGGING.FILE]\n [--logging.level LOGGING.LEVEL]\n\n optional arguments:\n -h, --help show this help message and exit\n --input_dir INPUT_DIR\n default: data\n --logging.file LOGGING.FILE\n default: output.log\n --logging.level LOGGING.LEVEL\n default: 4\n\nOverride settings using the command line\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n``python main.py --logging.file=other_log.txt``\n\nYou get your merged yaml + command line parameters in a convenient dictionary\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n::\n\n # exact same output format as normal yaml.load would produce\n {'input_dir': 'data', 'logging': {'file': 'other_log.txt', 'level': 4}}\n\nThe types used in the yaml file are automatically enforced\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nSetting the log-level to a string instead of an int: ``python main.py --logging.level=WARNING``\n \n\n::\n\n usage: main.py [-h] [--input_dir INPUT_DIR] [--logging.file LOGGING.FILE]\n [--logging.level LOGGING.LEVEL]\n main.py: error: argument --logging.level: invalid int value: 'WARNING'\n\nSetting the log-level to the correct type: ``python main.py --logging.level=0``\n \n\n::\n\n {'input_dir': 'data', 'logging': {'file': 'output.log', 'level': 0}}\n\nInstallation\n------------\n\n::\n\n pip install quickargs\n\nUsage\n-----\n\nLoad the yaml config and parse command line arguments\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nmain.py\n \n\n.. code:: python\n\n import yaml\n import quickargs\n\n with open(\"config.yaml\") as f:\n config = yaml.load(f, Loader=quickargs.YAMLArgsLoader)\n\nDeeply nested arguments are no problem\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nconfig.yaml\n \n\n.. code:: yaml\n\n key1:\n key2:\n key3:\n key4: value\n\nOverride nested argument using dot notation: ``python main.py --key1.key2.key3.key4=other_value``\n \n\n::\n\n {'key1': {'key2': {'key3': {'key4': 'other_value'}}}}\n\nOf course it is fine to just call your program without any command line arguments\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nHappy with the default values in config file: ``python main.py``\n \n\n::\n\n {'key1': {'key2': {'key3': {'key4': 'value'}}}}\n\nMost yaml types, including sequences are supported\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nconfig.yaml\n \n\n.. code:: yaml\n\n thresholds: [0.2, 0.4, 0.6, 0.8, 1.0]\n\nOverride the thresholds: ``python main.py --thresholds='[0.0, 0.5, 1.0]'``\n \n\n(take care to use ' ' around your command line arguments if they include\nspaces)\n\n::\n\n {'thresholds': [0.0, 0.5, 1.0]}\n\nHowever, types within sequences are not enforced\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nconfig.yaml\n \n\n.. code:: yaml\n\n thresholds: [0.2, 0.4, 0.6, 0.8, 1.0]\n\nList of strings instead of list of floats does not give an error: ``python main.py --thresholds=[a,b,c]``\n \n\n::\n\n {'thresholds': ['a', 'b', 'c']}\n\nYou can even pass references to functions or classes (your own or builtins)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nconfig.yaml\n \n\n.. code:: yaml\n\n function_to_call: !!python/name:yaml.dump\n\nOverride with reference to built-in zip function: ``python main.py --function_to_call=zip``\n \n\n::\n\n {'function_to_call': }\n\nExample with all supported types\n--------------------------------\n\nconfig.yaml\n \n\n.. code:: yaml\n\n an_int: 3\n a_float: 3.0\n a_bool: True\n a_complex_number: 37-880j\n\n a_date: 2016-12-11\n\n sequences:\n a_list: [a, b, c]\n # for tuples you need to use square [] brackeds in the yaml and on the command line\n # they will still be proper tuples in the result\n a_tuple: !!python/tuple [a, b]\n\n python:\n a_function: !!python/name:yaml.load\n a_class: !!python/name:yaml.loader.Loader\n a_module: !!python/module:contextlib\n # can be overwritten with any type\n a_none: !!python/none\n\nOverride every single parameter in the config file\n \n\n::\n\n python main.py --an_int=4 --a_float=2.0 --a_bool=False --a_complex_number=42-111j --a_date=2017-01-01 \\\n --sequences.a_list=[c,b,c] --sequences.a_tuple=[b,a] --python.a_function=zip \\\n --python.a_class=yaml.parser.Parser --python.a_module=yaml --python.a_none=1234\n\n::\n\n {'a_bool': False,\n 'a_complex_number': '42-111j',\n 'a_date': datetime.date(2017, 1, 1),\n 'a_float': 2.0,\n 'an_int': 4,\n 'python': {'a_class': ,\n 'a_function': ,\n 'a_module': ,\n 'a_none': None},\n 'sequences': {'a_list': ['c', 'b', 'c'], 'a_tuple': ('b', 'a')}}\n\nCurrently not supported\n-----------------------\n\nTypes\n^^^^^\n\nFollowing types are not supported at all:\n\n- !!python/dict (because it looks just like the rest of the yaml file)\n- !!pairs\n\nFollowing types are not enforced / objects will not be instantiated:\n\n- !!python/object\n- !!python/object/new\n- !!python/object/apply\n\nMulti-document loading\n^^^^^^^^^^^^^^^^^^^^^^\n\nIf the YAML file contains multiple documents, only the first document\nwill be considered. The ``yaml.load_all`` functionality is not\nsupported.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/krasch/quickargs", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "quickargs", "package_url": "https://pypi.org/project/quickargs/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/quickargs/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/krasch/quickargs" }, "release_url": "https://pypi.org/project/quickargs/0.1/", "requires_dist": null, "requires_python": null, "summary": "YAML config file -> command line interface", "version": "0.1" }, "last_serial": 2524717, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "779fc8da9008b2c99763ddca74a8da08", "sha256": "82c22e2a04de34ce67f33d5a9b2740a8a3507c1ff1b6129e053ed1e8c434068a" }, "downloads": -1, "filename": "quickargs-0.1.linux-x86_64.tar.gz", "has_sig": true, "md5_digest": "779fc8da9008b2c99763ddca74a8da08", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17341, "upload_time": "2016-12-17T13:03:37", "url": "https://files.pythonhosted.org/packages/99/a3/498615f3ffd7eea0fba85de5f086ee76d928fbcc7a52dce6976b8a16a679/quickargs-0.1.linux-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "f922dff4bb4a85252217efcd2833fccb", "sha256": "bf04897d1c474f670ec598a0c738db72ba54fe9c8720f196f411fa7c67902102" }, "downloads": -1, "filename": "quickargs-0.1-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "f922dff4bb4a85252217efcd2833fccb", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12744, "upload_time": "2016-12-17T13:03:33", "url": "https://files.pythonhosted.org/packages/18/20/ac9ba7a1332a34bb44ae45219820037bddc6689cc9fee56c9b768362280a/quickargs-0.1-py2.py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "779fc8da9008b2c99763ddca74a8da08", "sha256": "82c22e2a04de34ce67f33d5a9b2740a8a3507c1ff1b6129e053ed1e8c434068a" }, "downloads": -1, "filename": "quickargs-0.1.linux-x86_64.tar.gz", "has_sig": true, "md5_digest": "779fc8da9008b2c99763ddca74a8da08", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17341, "upload_time": "2016-12-17T13:03:37", "url": "https://files.pythonhosted.org/packages/99/a3/498615f3ffd7eea0fba85de5f086ee76d928fbcc7a52dce6976b8a16a679/quickargs-0.1.linux-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "f922dff4bb4a85252217efcd2833fccb", "sha256": "bf04897d1c474f670ec598a0c738db72ba54fe9c8720f196f411fa7c67902102" }, "downloads": -1, "filename": "quickargs-0.1-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "f922dff4bb4a85252217efcd2833fccb", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12744, "upload_time": "2016-12-17T13:03:33", "url": "https://files.pythonhosted.org/packages/18/20/ac9ba7a1332a34bb44ae45219820037bddc6689cc9fee56c9b768362280a/quickargs-0.1-py2.py3-none-any.whl" } ] }