Create ArgumentParser automatically from function signatures
Project description
Overview
A lightweight wrapper around argparse to help build CLIs from functions.
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 an optional parameter.
kw2: This is a boolean. Setting the flag sets it to True.
"""
print(locals())
arger = Arger(
main,
prog="pytest", # for testing purposes; otherwise, not required
)
if __name__ == "__main__":
arger.run()
-
Here
Argeris just a subclass ofArgumentParser. It does not prevent you from using standardargparsefeatures. -
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 an optional parameter. (default: None)
-w, --kw2 This is a boolean. Setting the flag sets it to True. (default: False)
$ python test.py 100 param2
{'param1': 100, 'param2': 'param2', 'kw1': None, 'kw2': False}
- Check out the examples folder and documentation to see more of
argerin action. It supports any level of sub-commands.
Features
- Uses the docstring to parse help descriptions for arguments. Supports:
- Flags will be generated from parameter names.
- E.g.,
def main(param: ...)->-p, --param - If needed, you can declare them inside the docstring, like
:param arg1: -a --arg this is the document.
- E.g.,
- One can use the
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 standard types are supported. Please see the examples for more supported types with code examples.
- No external dependency other than the standard library.
NOTE
*argsis supported, but there is no**kwargssupport yet.- Any optional argument starting with an underscore is not passed to the parser. They are considered private to the function's implementation. Some parameter names have special meaning:
_namespace_-> gets the output fromArgumentParser.parse_args()_arger_-> gets 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.2.2.tar.gz.
File metadata
- Download URL: arger-2.2.2.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6c6d193637509919994ee8f8f73210156f120a5d171a8f0853f1133ff8a5547
|
|
| MD5 |
08c78a1b71ee473498a13fac470bd78e
|
|
| BLAKE2b-256 |
7c81044720b56417795e57d7e03f7dd25c5d7f80e4dac40991e5014e02244371
|
Provenance
The following attestation bundles were made for arger-2.2.2.tar.gz:
Publisher:
publish.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.2.2.tar.gz -
Subject digest:
c6c6d193637509919994ee8f8f73210156f120a5d171a8f0853f1133ff8a5547 - Sigstore transparency entry: 1790933298
- Sigstore integration time:
-
Permalink:
jnoortheen/arger@bbeff6752d4bc360e4b9e45927944fc64facb548 -
Branch / Tag:
refs/tags/v2.2.2 - Owner: https://github.com/jnoortheen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bbeff6752d4bc360e4b9e45927944fc64facb548 -
Trigger Event:
release
-
Statement type:
File details
Details for the file arger-2.2.2-py3-none-any.whl.
File metadata
- Download URL: arger-2.2.2-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c40dabf608f2d2e36d39d789c2581b57af779a1c1061a1d21a2b70df2646cda
|
|
| MD5 |
d5be3d75be59fddf551348b651303ea3
|
|
| BLAKE2b-256 |
68dc13b6b44f7f51a454c7e07ebb49b84fa05159e1f0aece64fa4e15f278f526
|
Provenance
The following attestation bundles were made for arger-2.2.2-py3-none-any.whl:
Publisher:
publish.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.2.2-py3-none-any.whl -
Subject digest:
6c40dabf608f2d2e36d39d789c2581b57af779a1c1061a1d21a2b70df2646cda - Sigstore transparency entry: 1790933317
- Sigstore integration time:
-
Permalink:
jnoortheen/arger@bbeff6752d4bc360e4b9e45927944fc64facb548 -
Branch / Tag:
refs/tags/v2.2.2 - Owner: https://github.com/jnoortheen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bbeff6752d4bc360e4b9e45927944fc64facb548 -
Trigger Event:
release
-
Statement type: