ZParser2 Cli Argument Parsing Library
`zparser2` is probably the simplest most opinionated argument parsing library in python. Lot's of conventions, zero configuration!
All you have to do is add the `@z.task` notation to a function and it automatically become available to the CLI.
Perks:
* If a function contains annotations, it's variable types will be enforced and proper help will be displayed to the user.
* If a function contains a docstring, it will show up as the function's comment in the CLI.
* The file in which the function is located will be the module in which the function will be available.
* If a module contains a docstring, it will show as the module's documentation in the CLI
* If a function is in the main python script (`__main__`), it will be directly accessible, without needing to provide the module name.
The downside is that you can only have up two layers in your cli (app.py MODULE_NAME FUNCTION_NAME). That being said, more than that would be too complex.
Instalation
-----------
```
pip3 install zparser2
```
Example
-------
Let's say you have 3 files:
math_functions.py
```python
"""here we do math"""
from zparser2 import z
@z.task
def duplicate_number(x: float):
"""returns twice the value of x"""
return 2*x
@z.task
def triple_number(x: float):
"""returns 3 times the value of x"""
return 3*x
```
string_functions.py
```python
"""string processing"""
from zparser2 import z
@z.task
def add_square_brackets_to_string(x: str):
"""x -> [x]"""
return f"[{x}]"
@z.task
def first_word(x: str):
"""returns the first word of a string"""
return x.split(" ")[0]
@z.task
def last_word(x: str):
"""returns the last word of a string"""
return x.split(" ")[-1]
@z.task
def another_task(somestring: str, some_int: int, workdir=None, root_url=None):
"""description of the task"""
print(f"somestring={somestring}")
print(f"some_int={some_int}")
print(f"workdir={workdir}")
print(f"root_url={root_url}")
```
mycli.py
```python
#!/usr/bin/env python3
"""description of the __main__ module"""
from zparser2 import z, zparser2_init
import math_functions
import string_functions
@z.task
def say_hello(name: str):
"""this is a function on the main file"""
print(f"Hello {name}, welcome to zparser 2!")
if __name__ == "__main__":
zparser2_init()
```
Output
------
```
(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py
./mycli.py <task>
./mycli.py <plugin_name> <task>
Plugin list:
math_functions - here we do math
string_functions - string processing
Task list:
say_hello - this is a function on the main file
```
```
(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py string_functions
You need to specify a task
--------------------------------------------------------------------------------
string processing
./mycli.py string_functions <task>
Plugin alias: []
Tasks:
add_square_brackets_to_string - x -> [x]
another_task - description of the task
first_word - returns the first word of a string
last_word - returns the last word of a string
```
```
(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py string_functions another_task
You need to specify the required arguments [somestring, some_int]
--------------------------------------------------------------------------------
description of the task
Usage:
./mycli.py string_functions another_task somestring some_int [--workdir workdir] [--root_url root_url]
Positional arguments:
somestring - <class 'str'>
some_int - <class 'int'>
Optional arguments:
--workdir (Default: None) -
--root_url (Default: None) -
```
```
(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py string_functions another_task blah 42 --root_url https://blah.com
somestring=blah
some_int=42
workdir=None
root_url=https://blah.com
```
```
(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py say_hello Bob
Hello Bob, welcome to zparser 2!
```
How to build & publish
----------------------
* `python3 -m build`
* `python3 -m twine upload --repository testpypi dist/*`
* `python3 -m twine upload --repository pypi dist/*`
Raw data
{
"_id": null,
"home_page": null,
"name": "zparser2",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "cli, argument, parsing",
"author": "Marcos Diez, Benjamin Port",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/9e/be/3c6e57b2025af3cef40197b1f35a316b94fade739ba7cac82f4d1dc81e73/zparser2-0.0.11.tar.gz",
"platform": null,
"description": "ZParser2 Cli Argument Parsing Library\n\n\n`zparser2` is probably the simplest most opinionated argument parsing library in python. Lot's of conventions, zero configuration!\n\nAll you have to do is add the `@z.task` notation to a function and it automatically become available to the CLI.\n\nPerks:\n\n * If a function contains annotations, it's variable types will be enforced and proper help will be displayed to the user.\n * If a function contains a docstring, it will show up as the function's comment in the CLI.\n * The file in which the function is located will be the module in which the function will be available.\n * If a module contains a docstring, it will show as the module's documentation in the CLI\n * If a function is in the main python script (`__main__`), it will be directly accessible, without needing to provide the module name.\n\nThe downside is that you can only have up two layers in your cli (app.py MODULE_NAME FUNCTION_NAME). That being said, more than that would be too complex.\n\nInstalation\n-----------\n```\npip3 install zparser2\n```\n\nExample\n-------\n\nLet's say you have 3 files:\n\n\nmath_functions.py\n```python\n\"\"\"here we do math\"\"\"\nfrom zparser2 import z\n\n@z.task\ndef duplicate_number(x: float):\n \"\"\"returns twice the value of x\"\"\"\n return 2*x\n\n@z.task\ndef triple_number(x: float):\n \"\"\"returns 3 times the value of x\"\"\"\n return 3*x\n```\n\nstring_functions.py\n```python\n\"\"\"string processing\"\"\"\nfrom zparser2 import z\n\n@z.task\ndef add_square_brackets_to_string(x: str):\n \"\"\"x -> [x]\"\"\"\n return f\"[{x}]\"\n\n@z.task\ndef first_word(x: str):\n \"\"\"returns the first word of a string\"\"\"\n return x.split(\" \")[0]\n\n@z.task\ndef last_word(x: str):\n \"\"\"returns the last word of a string\"\"\"\n return x.split(\" \")[-1]\n\n@z.task\ndef another_task(somestring: str, some_int: int, workdir=None, root_url=None):\n \"\"\"description of the task\"\"\"\n print(f\"somestring={somestring}\")\n print(f\"some_int={some_int}\")\n print(f\"workdir={workdir}\")\n print(f\"root_url={root_url}\")\n```\n\n\nmycli.py\n```python\n#!/usr/bin/env python3\n\"\"\"description of the __main__ module\"\"\"\nfrom zparser2 import z, zparser2_init\nimport math_functions\nimport string_functions\n\n\n@z.task\ndef say_hello(name: str):\n \"\"\"this is a function on the main file\"\"\"\n print(f\"Hello {name}, welcome to zparser 2!\")\n\nif __name__ == \"__main__\":\n zparser2_init()\n\n```\n\nOutput\n------\n\n```\n(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py\n./mycli.py <task>\n./mycli.py <plugin_name> <task>\nPlugin list:\n math_functions - here we do math\n string_functions - string processing\nTask list:\n say_hello - this is a function on the main file\n\n```\n\n```\n(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py string_functions\nYou need to specify a task\n--------------------------------------------------------------------------------\nstring processing\n./mycli.py string_functions <task>\nPlugin alias: []\nTasks:\n add_square_brackets_to_string - x -> [x]\n another_task - description of the task\n first_word - returns the first word of a string\n last_word - returns the last word of a string\n```\n\n```\n(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py string_functions another_task\nYou need to specify the required arguments [somestring, some_int]\n--------------------------------------------------------------------------------\ndescription of the task\nUsage:\n ./mycli.py string_functions another_task somestring some_int [--workdir workdir] [--root_url root_url]\nPositional arguments:\n somestring - <class 'str'>\n some_int - <class 'int'>\nOptional arguments:\n --workdir (Default: None) -\n --root_url (Default: None) -\n```\n\n```\n(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py string_functions another_task blah 42 --root_url https://blah.com\nsomestring=blah\nsome_int=42\nworkdir=None\nroot_url=https://blah.com\n```\n\n```\n(env2) mdiez@batman:~/code/zparser2/example$ ./mycli.py say_hello Bob\nHello Bob, welcome to zparser 2!\n```\n\nHow to build & publish\n----------------------\n\n* `python3 -m build`\n* `python3 -m twine upload --repository testpypi dist/*`\n* `python3 -m twine upload --repository pypi dist/*`\n\n",
"bugtrack_url": null,
"license": null,
"summary": "ZParser Cli Argument Library. Nothing comes after Z",
"version": "0.0.11",
"project_urls": {
"Homepage": "https://github.com/marcosdiez/zparser2",
"Issues": "https://github.com/marcosdiez/zparser2/issues"
},
"split_keywords": [
"cli",
" argument",
" parsing"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "42f0b05fd2d9522b5318105737ce731be86482f73dfb02e18aac95fc0111d729",
"md5": "369b3ed296fc1d4d84ebf5f005f22273",
"sha256": "f4cf847c09637b2750c312198061133f76650f9def4e3c92d2f080f77a62b807"
},
"downloads": -1,
"filename": "zparser2-0.0.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "369b3ed296fc1d4d84ebf5f005f22273",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 8270,
"upload_time": "2025-07-08T21:40:17",
"upload_time_iso_8601": "2025-07-08T21:40:17.307029Z",
"url": "https://files.pythonhosted.org/packages/42/f0/b05fd2d9522b5318105737ce731be86482f73dfb02e18aac95fc0111d729/zparser2-0.0.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "9ebe3c6e57b2025af3cef40197b1f35a316b94fade739ba7cac82f4d1dc81e73",
"md5": "297a73b16ab9a34033e6474f1158fc26",
"sha256": "d64cd90951d6c42d099deb4b87475fef1d1a4461b565155f01e2b67415552213"
},
"downloads": -1,
"filename": "zparser2-0.0.11.tar.gz",
"has_sig": false,
"md5_digest": "297a73b16ab9a34033e6474f1158fc26",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 9559,
"upload_time": "2025-07-08T21:40:18",
"upload_time_iso_8601": "2025-07-08T21:40:18.594211Z",
"url": "https://files.pythonhosted.org/packages/9e/be/3c6e57b2025af3cef40197b1f35a316b94fade739ba7cac82f4d1dc81e73/zparser2-0.0.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-08 21:40:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "marcosdiez",
"github_project": "zparser2",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "zparser2"
}