{ "info": { "author": "Robert Wright", "author_email": "madman.bob@hotmail.co.uk", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# argparse_utils\n\n[`argparse_utils`](https://github.com/madman-bob/python-argparse-utils)\nprovides a collection of utilities for the Python standard-library\n[`argparse`](https://docs.python.org/3/library/argparse.html)\nmodule.\nThese utilities assist with parsing command-line arguments to Python objects.\n\n## Example\n\nConsider a simple command-line script which accepts a colour as it's only argument,\nand immediately prints the Python representation of that object.\n\n```python\nfrom argparse import ArgumentParser\nfrom enum import Enum\n\nfrom argparse_utils import enum_action\n\nclass Colours(Enum):\n red = 1\n green = 2\n blue = 3\n\nif __name__ == \"__main__\":\n parser = ArgumentParser()\n parser.add_argument('colour', action=enum_action(Colours))\n\n arguments = parser.parse_args()\n\n print(repr(arguments.colour))\n```\n\n```bash\n$ argparse_utils_example.py red\n\n```\n\nWithout the `enum_action` action, `arguments.colour` would be the string `'red'`,\nrather than the enum value `Colours.red`.\nWhat's more, the action ensures that only the values given in the enum are allowed,\ninstead of any string value.\n\n## Reference\n\n- `datetime_action(fmt='%Y-%m-%dT%H:%M:%S')`\n\n Maps command-line arguments in the given format to `datetime` objects.\n Only accepts valid date-times in that format.\n\n eg. An action of `datetime_action()` would map a command-line argument of\n `2000-01-01T00:00:00` to the Python object `datetime.datetime(2000, 1, 1, 0, 0)`.\n\n- `date_action(fmt='%Y-%m-%d')`\n\n Maps command-line arguments in the given format to `date` objects.\n Only accepts valid dates in that format.\n\n eg. An action of `date_action()` would map a command-line argument of\n `2000-01-01` to the Python object `datetime.date(2000, 1, 1)`.\n\n- `time_action(fmt='%H:%M:%S')`\n\n Maps command-line arguments in the given format to `time` objects.\n Only accepts valid times in that format.\n\n eg. An action of `time_action()` would map a command-line argument of\n `00:00:00` to the Python object `datetime.time(0, 0)`.\n\n- `timedelta_action(fmt='%H:%M:%S')`\n\n Maps command-line arguments in the given format to `timedelta` objects.\n Only accepts valid time-deltas in that format.\n\n Note: As this uses a `timedelta` object, this may behave in unexpected ways when attempting to use months or years.\n\n eg. An action of `timedelta_action()` would map a command-line argument of\n `01:00:00` to the Python object `datetime.timedelta(0, 3600))`.\n\n- `json_action(**kwargs)`\n\n Maps command-line arguments to JSON objects.\n Only accepts valid JSON.\n Passes `kwargs` on to `json.loads`.\n\n eg. An action of `json_action()` would map a command-line argument of\n `{\"a\": 1, \"b\": 2}` to the Python object `{\"a\": 1, \"b\": 2}`.\n\n- `mapping_action(possible_values)`\n\n Takes a dictionary whose keys are the allowed values,\n and maps those values to the values found in the dictionary.\n Only the values found as keys in the dictionary are allowed as command-line arguments.\n\n eg. An action of\n\n ```python\n mapping_action({\n 'red': (255, 0, 0),\n 'green': (0, 255, 0),\n 'blue': (0, 0, 255)\n })\n ```\n\n would map a command-line argument of `red` to the Python object `(255, 0, 0)`.\n\n- `enum_action(enum_class)`\n\n Takes an `Enum` class,\n and maps the string representation of the keys to the appropriate enum value.\n Only the values found in the enum are allowed as command-line arguments.\n\n eg. Using the `Colour` enum, from the first example, an action of\n\n ```python\n enum_action(Colour)\n ```\n\n would map a command-line argument of `red` to the enum `Colour.red` value.\n\n- `python_literal_action()`\n\n Maps command-line arguments to Python literals.\n Only accepts valid Python literal objects.\n\n Similar to `json_action`, but also allows tuples, and complex numbers.\n\n eg. An action of `python_literal_action()` would map a command-line argument of\n `(1, 2)` to the Python object `(1, 2)`.\n\n## Installation\n\nInstall and update using the standard Python package manager\n[pip](https://pip.pypa.io/en/stable/):\n\n```bash\npip install argparse-utils\n```\n\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/madman-bob/python-argparse-utils", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "argparse-utils", "package_url": "https://pypi.org/project/argparse-utils/", "platform": "", "project_url": "https://pypi.org/project/argparse-utils/", "project_urls": { "Homepage": "https://github.com/madman-bob/python-argparse-utils" }, "release_url": "https://pypi.org/project/argparse-utils/1.2.0/", "requires_dist": null, "requires_python": ">=2.7", "summary": "A collection of utilities for the Python standard-library argparse module", "version": "1.2.0" }, "last_serial": 4268153, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "0a9a84598d13b21c89eba05b4eb1d5c9", "sha256": "21a8860cf8af89c2fd3a635f4fc3e7edaa1c7708907c4ec1be3ca214ab14eda9" }, "downloads": -1, "filename": "argparse_utils-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "0a9a84598d13b21c89eba05b4eb1d5c9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=2.7", "size": 2929, "upload_time": "2018-09-06T16:18:08", "url": "https://files.pythonhosted.org/packages/08/da/fc2a67ff374d80360c5590cc8a8e79684f15ed6b7ab3c2aa14e23147c887/argparse_utils-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "101861ef8a19cb6de36363dfdfb74f28", "sha256": "25a81b3e286ea8002491a3188053722927931895d0fa75fc7da281265d114365" }, "downloads": -1, "filename": "argparse_utils-1.0.0.tar.gz", "has_sig": false, "md5_digest": "101861ef8a19cb6de36363dfdfb74f28", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 2323, "upload_time": "2018-09-06T16:18:09", "url": "https://files.pythonhosted.org/packages/3f/cb/b10909dd98f03ee0638ca031eeaad012328ccaa0c6f64c98b23b57b707e0/argparse_utils-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "7b661b40372f8737a4da5781a3326f57", "sha256": "248b5bb96955d10e5fa82844dcd6231bfecac8f9ad770739db8b8440dc1656e0" }, "downloads": -1, "filename": "argparse_utils-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "7b661b40372f8737a4da5781a3326f57", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=2.7", "size": 2929, "upload_time": "2018-09-06T16:16:33", "url": "https://files.pythonhosted.org/packages/b3/1f/54144cea362191192367c7e4e13403678de9e595ca514cbad42bacc75589/argparse_utils-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0adedfe064faea6998eac00e31df171c", "sha256": "408a9046924db27fc0a193ca572c33542dbb4b6167e965941eba950ba6621167" }, "downloads": -1, "filename": "argparse_utils-1.1.0.tar.gz", "has_sig": false, "md5_digest": "0adedfe064faea6998eac00e31df171c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 2327, "upload_time": "2018-09-06T16:16:34", "url": "https://files.pythonhosted.org/packages/8b/a5/f3fc4327069c51fe9225829c0c6de754a8d0e1d9d76805f66a5b93f67b11/argparse_utils-1.1.0.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "80d2b091724581260eb08723191cf50a", "sha256": "512f5d78e9ca14647a402058b8b8a1f5b476ba0b30bf0fba5b55cc742d20c364" }, "downloads": -1, "filename": "argparse_utils-1.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "80d2b091724581260eb08723191cf50a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=2.7", "size": 5550, "upload_time": "2018-09-13T09:41:33", "url": "https://files.pythonhosted.org/packages/a2/88/83227583f5a45f6d51b04a16890875e1834e2080525aaf1f4223d3b34fae/argparse_utils-1.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "39793079e2964fb28c19274863d9f865", "sha256": "9c0892b5be53642ef5c1db4c06dcabd448d2135f40f6b0098f0b5524c60a4cad" }, "downloads": -1, "filename": "argparse_utils-1.2.0.tar.gz", "has_sig": false, "md5_digest": "39793079e2964fb28c19274863d9f865", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 3864, "upload_time": "2018-09-13T09:41:34", "url": "https://files.pythonhosted.org/packages/83/da/484263101336d0c0b9c9b8f78c90b832f5997da1888d67e738833a2ed5d3/argparse_utils-1.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "80d2b091724581260eb08723191cf50a", "sha256": "512f5d78e9ca14647a402058b8b8a1f5b476ba0b30bf0fba5b55cc742d20c364" }, "downloads": -1, "filename": "argparse_utils-1.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "80d2b091724581260eb08723191cf50a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=2.7", "size": 5550, "upload_time": "2018-09-13T09:41:33", "url": "https://files.pythonhosted.org/packages/a2/88/83227583f5a45f6d51b04a16890875e1834e2080525aaf1f4223d3b34fae/argparse_utils-1.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "39793079e2964fb28c19274863d9f865", "sha256": "9c0892b5be53642ef5c1db4c06dcabd448d2135f40f6b0098f0b5524c60a4cad" }, "downloads": -1, "filename": "argparse_utils-1.2.0.tar.gz", "has_sig": false, "md5_digest": "39793079e2964fb28c19274863d9f865", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 3864, "upload_time": "2018-09-13T09:41:34", "url": "https://files.pythonhosted.org/packages/83/da/484263101336d0c0b9c9b8f78c90b832f5997da1888d67e738833a2ed5d3/argparse_utils-1.2.0.tar.gz" } ] }