{ "info": { "author": "gwenzek", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": "# func_argparse\n\nGenerate a nice command line interface for a list of functions or a module, leveraging your doc-strings and type annotations.\nNever worry about your Argparser being out of sync with your code.\nTry it with `pip install func_argparse`.\n\n## Example\n\nIn a 'hello.py' file:\n```py\n\"\"\"Say hello or goodbye to the user.\"\"\"\n\nimport func_argparse\n\n\ndef hello(user: str, times: int = None):\n \"\"\"Say hello.\n\n Arguments:\n user: name of the user\n \"\"\"\n print(f\"Hello {user}\" * (1 if times is None else times))\n\n\ndef bye(user: str, see_you: float = 1.0):\n \"\"\"Say goodbye.\"\"\"\n print(f\"Goodbye {user}, see you in {see_you:.1f} days\")\n\n\nif __name__ == \"__main__\":\n func_argparse.main()\n```\n\nFrom CLI:\n```\n$ python hello.py hello --user gwenzek\nHello gwenzek\n\n$ python hello.py hello --user gwenzek --times 2\nHello gwenzekHello gwenzek\n\n$ python hello.py bye --user gwenzek --see_you 12.345\nGoodbye gwenzek, see you in 12.3 days\n\n$ python hello.py hello -u gwenzek -t 1\nHello gwenzek\n\n$ python hello.py --help\nusage: hello.py [-h] {hello,bye} ...\n\nSay hello or goodbye to the user.\n\npositional arguments:\n {hello,bye}\n hello Say hello.\n bye Say goodbye.\n\noptional arguments:\n -h, --help show this help message and exit\n\n$ python hello.py bye --help\nusage: hello.py bye [-h] -u USER [-s SEE_YOU]\n\noptional arguments:\n -h, --help show this help message and exit\n -u USER, --user USER\n -s SEE_YOU, --see_you SEE_YOU\n (default=1.0)\n```\n\n\n## Gotchas\n\n- `func_argparse` generate classics `argparse.Argparser` you can mix and match them with hand-written parsers.\n- `func_argparse.main()` create one CLI command by \"public\" function from a file / module.\n- Use `func_argparse.single_main(my_main)` if you only have one entry point in your file.\n- All functions arguments need a type hint.\n- Arguments without default value will be marked as required.\n- A boolean argument `a` will generate two flags: `--a` and `--no-a`.\n- A boolean argument with no default value will be assumed to default to `False`.\n- The first argument starting with letter `a` will also be available with the flag `-a`.\n- The function docstring will be parsed to extract the help messages.\n - First line is used as help message for the function\n - First line starting with `a` will be used to extract the documentation for argument `a`.\n Spaces, dashes and columns will be stripped before displaying.\n- Some kind of functions (notably builtin and C-function) can't be inspected and\n we can't generate Argparser for them.\n- You can't have a function with an argument named `__command` when using `main` or `multi_parser`.\n- If you don't like the generated parser, you can modify it using `override` function.\n\n\n## Alternatives\n\nHere are other alternatives you might be interested in.\n\n- [argparse](https://docs.python.org/3/library/argparse.html): the builtin library upon which `func_argparse` is built. Grants a very precise control on the CLI but is a bit verbose and prone to go out-of-sync with the code.\n- [fire](https://github.com/google/python-fire): also generates parser with introspection but doesn't leverage types. So the types of arguments is determined at parse time. Can generate completion files.\n- [click](https://palletsprojects.com/p/click/): uses function annotations to generate the CLI.\n\n## Contibuting\n\nAll contributions are welcome.\nCode formatting is enforced with `isort`, `black`.\nTypes annotations are required for the main module and checked with `mypy`.\nTests are run with `pytest`.\n\nRun `pip install \".[dev]\"` to install the required modules\nRun `./tools.sh all` to format your code and run `mypy` and `pytest`.\n\n\n## TODOs\n\n* Add all parameters from `add_argument` to `override`\n* Chose one from Circle CI and Github Workflows\n* Make it easy to parse a comma separated list of argument\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/gwenzek/func_argparse", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "func-argparse", "package_url": "https://pypi.org/project/func-argparse/", "platform": "", "project_url": "https://pypi.org/project/func-argparse/", "project_urls": { "Homepage": "https://github.com/gwenzek/func_argparse" }, "release_url": "https://pypi.org/project/func-argparse/1.1.1/", "requires_dist": [ "mypy (>=0.730) ; extra == 'dev'", "pytest ; extra == 'dev'", "black ; extra == 'dev'", "isort ; extra == 'dev'" ], "requires_python": "", "summary": "Generate CLI ArgumentParser from a function signature.", "version": "1.1.1", "yanked": false, "yanked_reason": null }, "last_serial": 6346896, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "b00ae4b5e182045e1f6c3085c45f3452", "sha256": "7667b73912bdc0dc15bcadcfc76fbb8ce6d441846fdbda186c4ba698c196256c" }, "downloads": -1, "filename": "func_argparse-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b00ae4b5e182045e1f6c3085c45f3452", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8736, "upload_time": "2019-09-18T15:15:54", "upload_time_iso_8601": "2019-09-18T15:15:54.026122Z", "url": "https://files.pythonhosted.org/packages/2d/5b/666a1d4b17836b6f63f9b19b86acbfdd4e433d35727cd5aa9761bf466dd3/func_argparse-1.0.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "9dffc5224348d7f306eab4858bb3d020", "sha256": "6477889334e9c98be5a3a255bf436aafcd0e72fedcbdf337b6cc5a7b89644f24" }, "downloads": -1, "filename": "func_argparse-1.0.0.tar.gz", "has_sig": false, "md5_digest": "9dffc5224348d7f306eab4858bb3d020", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7552, "upload_time": "2019-09-18T15:15:56", "upload_time_iso_8601": "2019-09-18T15:15:56.101001Z", "url": "https://files.pythonhosted.org/packages/73/c9/ef4dd43b2f109fadb0f748184d0f80c91f2920c6084f148575e100191216/func_argparse-1.0.0.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "574886e1501652648f7891974310596c", "sha256": "f2f93302ed726939bcfd9aa973724dc2d810961f91fd0628922416c72f3bcd22" }, "downloads": -1, "filename": "func_argparse-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "574886e1501652648f7891974310596c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9846, "upload_time": "2019-09-18T15:33:30", "upload_time_iso_8601": "2019-09-18T15:33:30.611702Z", "url": "https://files.pythonhosted.org/packages/5b/8b/1f0280b7559b0a61f7c6a2281a4a0b8deff1709a43e5cd37b6716df28323/func_argparse-1.0.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "56eacf050af82685cbb5761419583a3b", "sha256": "0c6ff0be8f6d7f3c7f7655ce2c8afa06203db9ea6b9d2e5bcd2b10e5852876e9" }, "downloads": -1, "filename": "func_argparse-1.0.1.tar.gz", "has_sig": false, "md5_digest": "56eacf050af82685cbb5761419583a3b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6756, "upload_time": "2019-09-18T15:33:32", "upload_time_iso_8601": "2019-09-18T15:33:32.087964Z", "url": "https://files.pythonhosted.org/packages/af/7e/2c4bf1814ddc461f5edb4ce2e31796e2c877ca56cda46ac36dc96ae2f11b/func_argparse-1.0.1.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "1b6cdb10403f43dbe3ca66d5d33257ef", "sha256": "35d02027fe367bcfe832dc39ce10b6fe4ae80ee7ae19889b1fad26eb64042578" }, "downloads": -1, "filename": "func_argparse-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "1b6cdb10403f43dbe3ca66d5d33257ef", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10018, "upload_time": "2019-09-23T20:16:59", "upload_time_iso_8601": "2019-09-23T20:16:59.430105Z", "url": "https://files.pythonhosted.org/packages/cf/9a/60fdc9fc517300803fa495f4e02f795981bd89fa4359df9a5b555409e631/func_argparse-1.0.2-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "1c5d255e3133edc5680dd88f915d4cae", "sha256": "d7e3432d61edcd6c0062971c0d24d0e71391a98ae80d502a84ec27984b5adf2b" }, "downloads": -1, "filename": "func_argparse-1.0.2.tar.gz", "has_sig": false, "md5_digest": "1c5d255e3133edc5680dd88f915d4cae", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6900, "upload_time": "2019-09-23T20:17:01", "upload_time_iso_8601": "2019-09-23T20:17:01.757491Z", "url": "https://files.pythonhosted.org/packages/8c/f5/472a05a57abc2f18b40c34d69da16a8e18158febfe4f69526ae93f622c77/func_argparse-1.0.2.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "9983caa01c01aed801a4673c08a040de", "sha256": "1928b2f00fe9f2a0d93ff349590cba4a293c9d5c2c580c6a573d5cf1dd0df02f" }, "downloads": -1, "filename": "func_argparse-1.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "9983caa01c01aed801a4673c08a040de", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8835, "upload_time": "2019-10-22T13:03:42", "upload_time_iso_8601": "2019-10-22T13:03:42.407854Z", "url": "https://files.pythonhosted.org/packages/e9/5e/b3f821ebfefd101e6b18c18f3bbe8b3180f63bd010b4bf761e969c69c13a/func_argparse-1.0.3-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "894217c980225ad33e8aa1179cf46785", "sha256": "40cb5933b0ac12a67646af61c8d1a26093f651fb28b3bb6d391de557ed676a15" }, "downloads": -1, "filename": "func_argparse-1.0.3.tar.gz", "has_sig": false, "md5_digest": "894217c980225ad33e8aa1179cf46785", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7322, "upload_time": "2019-10-22T13:03:43", "upload_time_iso_8601": "2019-10-22T13:03:43.774782Z", "url": "https://files.pythonhosted.org/packages/4d/01/8b7c263aa2304e25203a872df31b2e3d3b8e87d610b7c5092f259db1e1a9/func_argparse-1.0.3.tar.gz", "yanked": false, "yanked_reason": null } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "c2a0bd692b7a4bd7db547bb6ef734d3d", "sha256": "1e07f0c162a64b38bb84bfdeb7235408be15aa073146b8e830cbebfe0c4121e4" }, "downloads": -1, "filename": "func_argparse-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c2a0bd692b7a4bd7db547bb6ef734d3d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9954, "upload_time": "2019-12-22T07:24:13", "upload_time_iso_8601": "2019-12-22T07:24:13.121019Z", "url": "https://files.pythonhosted.org/packages/41/2c/9d14390a763aed4788df27d856463e6008aa8db1e86b14f8843f71045ef3/func_argparse-1.1.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "f6cd0a0d1fb054c38b364aa2878f73c8", "sha256": "5820a2ecb9586b8f96a8a5f7200a89eb853a9840ef087e61a563b22a049128ad" }, "downloads": -1, "filename": "func_argparse-1.1.0.tar.gz", "has_sig": false, "md5_digest": "f6cd0a0d1fb054c38b364aa2878f73c8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6960, "upload_time": "2019-12-22T07:24:14", "upload_time_iso_8601": "2019-12-22T07:24:14.643763Z", "url": "https://files.pythonhosted.org/packages/e1/39/0d0e0111a1f8335bf3e001c8987af321ad41b92b13274b2315ead32c3095/func_argparse-1.1.0.tar.gz", "yanked": false, "yanked_reason": null } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "590051efaa76b30705824b5d832fb28c", "sha256": "0a530c93ff18e838e486ced9e6b8b606a1cb184627f78d88e978c2e099426bf5" }, "downloads": -1, "filename": "func_argparse-1.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "590051efaa76b30705824b5d832fb28c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9949, "upload_time": "2019-12-22T08:32:21", "upload_time_iso_8601": "2019-12-22T08:32:21.932455Z", "url": "https://files.pythonhosted.org/packages/2e/37/e0a393069282714a357558734d6a11f989ef8a19a9939926ff35d75e22d7/func_argparse-1.1.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "85b39d012b4d9016b470ce9b02a891a4", "sha256": "a61bafc642c0ba711c51567fcd860526ec40de72bfafccad9c2a9b49c166166b" }, "downloads": -1, "filename": "func_argparse-1.1.1.tar.gz", "has_sig": false, "md5_digest": "85b39d012b4d9016b470ce9b02a891a4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6960, "upload_time": "2019-12-22T08:32:23", "upload_time_iso_8601": "2019-12-22T08:32:23.455765Z", "url": "https://files.pythonhosted.org/packages/98/a4/79adbdacbfbaea11efb7dc2cf91e5db2e3fb56b17e5eb27bb0c82a9f0111/func_argparse-1.1.1.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "590051efaa76b30705824b5d832fb28c", "sha256": "0a530c93ff18e838e486ced9e6b8b606a1cb184627f78d88e978c2e099426bf5" }, "downloads": -1, "filename": "func_argparse-1.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "590051efaa76b30705824b5d832fb28c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9949, "upload_time": "2019-12-22T08:32:21", "upload_time_iso_8601": "2019-12-22T08:32:21.932455Z", "url": "https://files.pythonhosted.org/packages/2e/37/e0a393069282714a357558734d6a11f989ef8a19a9939926ff35d75e22d7/func_argparse-1.1.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "85b39d012b4d9016b470ce9b02a891a4", "sha256": "a61bafc642c0ba711c51567fcd860526ec40de72bfafccad9c2a9b49c166166b" }, "downloads": -1, "filename": "func_argparse-1.1.1.tar.gz", "has_sig": false, "md5_digest": "85b39d012b4d9016b470ce9b02a891a4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6960, "upload_time": "2019-12-22T08:32:23", "upload_time_iso_8601": "2019-12-22T08:32:23.455765Z", "url": "https://files.pythonhosted.org/packages/98/a4/79adbdacbfbaea11efb7dc2cf91e5db2e3fb56b17e5eb27bb0c82a9f0111/func_argparse-1.1.1.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }