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()
-
Here Arger is just a subclass of
ArgumentParser. It will not conceal you from using otherargparselibraries. -
run this normally with
python test.py 100 param2
- Checkout examples folder and documentation to see more of
argerin action. It supports any level of sub-commands.
Features
-
Uses docstring to parse help comment for arguments. Supports
-
Flags will be generated from parameter-name.
- e.g.
def main(param: ...)->-p, --param - If needed you could declare it inside docstring like
:param arg1: -a --arg this is the document.
- e.g.
-
one can use
Argumentclass to pass any values to the parser.add_argument function -
The decorated functions can be composed to form nested sub-commands of any level.
-
Most of the Standard types supported. Please see examples for more supported types with examples.
NOTE
*argssupported but no**kwargssupport yet.- all optional arguments that start with underscore is not passed to
Parser. They are considered private to the function implementation. Some parameter names with special meaning
_namespace_-> to get the output from theArgumentParser.parse_args()_arger_-> to get the parser instance
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file arger-1.3.8.tar.gz.
File metadata
- Download URL: arger-1.3.8.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.5 CPython/3.8.8 Linux/5.4.0-1043-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beabb2c22ee2b4137831d453c86a3df1a605bbf7a4fb9d6e9fb4c1e8010db009
|
|
| MD5 |
6aabc6cc7a1b2b03034b85e02d718da2
|
|
| BLAKE2b-256 |
aec1f15b05c14d4b99519b0f6c0c2368c5856c566f1b4a0f61911c896ec372fa
|
File details
Details for the file arger-1.3.8-py3-none-any.whl.
File metadata
- Download URL: arger-1.3.8-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.5 CPython/3.8.8 Linux/5.4.0-1043-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86fa42b5d355aff67cae5206d027c05216a641893aec5a965a91c2d7aebd499d
|
|
| MD5 |
3316d75feb5f10fe21754a18488b4cd1
|
|
| BLAKE2b-256 |
5cd5b1f44d062ff61b3a48768b160a7ef2be61b62e3bfaca615fef56939bb975
|