Create argparser automatically from function signatures
Project description
Overview
A wrapper around stdlib argparse to help build CLIs from functions using type-hints :snake:.
Setup
:gear: Installation
Install it directly into an activated virtual environment:
$ pip install 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.
Args:
param1: The first parameter.
param2: The second parameter.
kw1: this is optional parameter.
kw2: this is boolean. setting flag sets True.
"""
print(locals())
arger = Arger(
main,
prog="pytest", # for testing purpose. otherwise not required
)
if __name__ == "__main__":
arger.run()
-
Here Arger is just a subclass of
ArgumentParser. It will not conceal you from using otherargparselibraries. -
run this normally with
$ python test.py -h
usage: pytest [-h] [-k KW1] [-w] param1 param2
Example function with types documented in the docstring.
positional arguments:
param1 The first parameter.
param2 The second parameter.
optional arguments:
-h, --help show this help message and exit
-k KW1, --kw1 KW1 this is optional parameter. (default: None)
-w, --kw2 this is boolean. setting flag sets True. (default: False)
$ python test.py 100 param2
{'param1': 100, 'param2': 'param2', 'kw1': None, 'kw2': False}
- 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.
- No external dependency other than stdlib.
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-2.1.0.tar.gz.
File metadata
- Download URL: arger-2.1.0.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52d70889996b0e866f6c5a8f1a342649818847c1491c26bd30a98765172543eb
|
|
| MD5 |
872e8f07ceaa41bb86e0f939b4dd9965
|
|
| BLAKE2b-256 |
66d3b1bc9306224de8e3435d6f333576a5b3037d18426a8d77ff15f79123abc5
|
Provenance
The following attestation bundles were made for arger-2.1.0.tar.gz:
Publisher:
ci.yml on jnoortheen/arger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
arger-2.1.0.tar.gz -
Subject digest:
52d70889996b0e866f6c5a8f1a342649818847c1491c26bd30a98765172543eb - Sigstore transparency entry: 262127772
- Sigstore integration time:
-
Permalink:
jnoortheen/arger@9617f5a6483c995512e360d9300f974d1917d73b -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/jnoortheen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@9617f5a6483c995512e360d9300f974d1917d73b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file arger-2.1.0-py3-none-any.whl.
File metadata
- Download URL: arger-2.1.0-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ebb00f10464030528c68543276dd92226e99ce4b34b56fd78b58ef423c58324
|
|
| MD5 |
0c57dc9e999bcec9b08e32213f06bfd5
|
|
| BLAKE2b-256 |
9e4dac5f90ace7bf85e44cb153a95b2771bdbdc9f2fe8cbfaa91fb85496506b3
|
Provenance
The following attestation bundles were made for arger-2.1.0-py3-none-any.whl:
Publisher:
ci.yml on jnoortheen/arger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
arger-2.1.0-py3-none-any.whl -
Subject digest:
1ebb00f10464030528c68543276dd92226e99ce4b34b56fd78b58ef423c58324 - Sigstore transparency entry: 262127781
- Sigstore integration time:
-
Permalink:
jnoortheen/arger@9617f5a6483c995512e360d9300f974d1917d73b -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/jnoortheen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@9617f5a6483c995512e360d9300f974d1917d73b -
Trigger Event:
workflow_dispatch
-
Statement type: