func2argparse
Converts annotated python functions to argparsers.
func2argparse uses type hints and default values in function signatures and combines them together with the docstring of the function to create an argument parser out of it.
Choices for arguments are taken from the docstrings as demonstrated in the example below.
Boolean arguments must always be default False.
Documentation & Installation
pip install func2argparse
Examples
from pathlib import Path
def foo(
x: int,
y: Path,
z: int = 54,
w: list[str] = ("hey", "ho"),
k: str = "choice1",
ll: list[int] = None,
flg: bool = False,
lb: list[bool] = True,
):
"""This is a test function
Parameters
----------
x : int
First arg
y : Path
Second arg
z : int
Third arg
w : list[str]
Fourth arg.
Multiline documentation
k : str, choices=("choice1", "choice2")
Fifth arg
ll : list[int]
This is an empty list
flg : bool
Set to True to do something
lb : list[bool]
A list of boolean values
Examples
--------
>>> foo()
"""
print(locals())
from func2argparse import func_to_manifest, manifest_to_argparser
manifest = func_to_manifest(foo)
parser = manifest_to_argparser(manifest, exit_on_error=False)
parser.print_help()
usage: This [-h] --x X --y Y [--z Z] [--w W [W ...]] [--k {choice1,choice2}] [--ll LL [LL ...]] [--flg] [--lb LB [LB ...]]
options:
-h, --help show this help message and exit
--x X, -x X First arg (default: None)
--y Y, -y Y Second arg (default: None)
--z Z, -z Z Third arg (default: 54)
--w W [W ...], -w W [W ...]
Fourth arg. Multiline documentation (default: ('hey', 'ho'))
--k {choice1,choice2}, -k {choice1,choice2}
Fifth arg (default: choice1)
--ll LL [LL ...], -l LL [LL ...]
This is an empty list (default: None)
--flg, -f Set to True to do something (default: False)
--lb LB [LB ...], -lb LB [LB ...]
A list of boolean values (default: True)
Metadata
Release files for func2argparse 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| func2argparse-0.1.8.tar.gz | 9.4 kB | Without provenance | Details for func2argparse-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| func2argparse-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for func2argparse-0.1.8-py3-none-any.whl |
Total release size: 16.3 kB
Release files / func2argparse-0.1.8.tar.gz
| Download URL | func2argparse-0.1.8.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d975da3c56981bc1375226a2883022ea6c9978b82bd015543494f2416db5e17c
|
|
BLAKE2b-256 checksum How to use checksums |
ea3e7acbc45f9f919c34ab2b6e796504276adf422bc6cf478a5d307dfafb0667
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / func2argparse-0.1.8-py3-none-any.whl
| Download URL | func2argparse-0.1.8-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4fe98911f8e2dec4d28c28a1782f1da6a6027d92b2046810b353fc0df2398d45
|
|
BLAKE2b-256 checksum How to use checksums |
92bf9e85a96af0a805577e5b1fe1741291d13ac24cd89d377aaed8ad60afd71f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for func2argparse 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.