Create argparser automatically from functions
Project description
Overview
A wrapper around argparser to help build CLIs from functions. Uses type-hints extensively :snake:.
Setup
:gear: Installation
Install it directly into an activated virtual environment:
$ pip install arger
or add it to your Poetry project:
$ poetry add arger
:books: Usage
- create a python file called test.py
from arger import Arger
def main(param1: int, param2: str, kw1=None, kw2=False):
"""Example function with types documented in the docstring.
:param param1: The first parameter.
:param param2: The second parameter.
"""
print(locals())
if __name__ == '__main__':
Arger(main).run()
- run this normally with
python test.py 100 param2
- Checkout examples folder and documentation to see more of
arger
in action.
Features
- Uses docstring to parse help comment for arguments. Supports
- Flags will be generated from parameter-name.
If needed you could declare it inside docstring like
:param arg1: -a --arg this is the document
. Also one can usedef main(arg1:int=Option('-a', '--arg')): ...
- The decorated functions can be composed to form nested sub-commands of any level.
- No external lib dependency
- Standard types supported. Please see examples for more supported types with examples.
- All argument to
ArgumentParser.add_argument
is supported. It can be updated witharger.Argument
orarger.Option
classes. *args
supported but no**kwargs
support yet.- all optional arguments that start with underscore is not passed to
Parser
. They are considered private to the function implementation. One can use_namespace_
to get the output from theArgumentParser.parse_args()
Similar Projects
argh
- has similar goals as to ease up using argparser.
- doesn't support type hints.
- No recent releases.
typer
- if you are using
click
, I highly recommend you to check this library. - it is neat and many features are drawn from it.
- doesn't support loading help text for arguments from docstrings.
invoke
- doesn't support type hints.
cliche
- has similar goals.
- doesn't cover much use cases as
arger
.
cliar
- no docstring support for help argument.
Recommended Alternatives
Projects that I didn't know while creating this project. I highly recommend you to checkout them.
This project was generated with cookiecutter using jacebrowning/template-python.
Argparser enhancements
- web-ui : https://github.com/nirizr/argparseweb
- extra actions : https://github.com/kadimisetty/action-hero
- automatic shell completions using argcomplete
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
arger-1.0.8.tar.gz
(11.9 kB
view details)
Built Distribution
arger-1.0.8-py3-none-any.whl
(10.7 kB
view details)
File details
Details for the file arger-1.0.8.tar.gz
.
File metadata
- Download URL: arger-1.0.8.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.4.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3ea06c2a53ea6f7afe40ea03fcabf11c445a9e7638348749505b41f1959aab2 |
|
MD5 | c1d8330d62247899a67ab5db0ad2e561 |
|
BLAKE2b-256 | f2a0c79629568489fa8615a1928f298359efbf2c8691f0c20201b6f3cecd9ff8 |
File details
Details for the file arger-1.0.8-py3-none-any.whl
.
File metadata
- Download URL: arger-1.0.8-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.4.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06f3ed25d3a3347341ca0c384da603e868cfd21ec3d2192099483d8efba5859e |
|
MD5 | 0026f42e5aca7f99d7f176f12ee93d45 |
|
BLAKE2b-256 | f0d6e704c8c06621c9a987f981de7271ccc810b8e46876e15ec4986cac16f822 |