paramspecli
paramspecli is a facade for the venerable argparse. It's simple, composable, and fun. But, most important, it's type-safe thanks to the ParamSpec magic.
Quick start
from paramspecli import Command, argument, option, flag
def ping(addr: str, *, until_stopped: bool, count: int | None):
print(f"Pinging {addr} ...")
cli = Command(ping, prog="ping")
cli.bind(
-argument("IP"),
until_stopped=-flag("-t"),
count=-option("-n", type=int),
)
result = cli.parse()
result()
Running it:
$ python ping.py -t -n 10 127.0.0.1
Pinging 127.0.0.1 ...
Type checker catches common errors:
cli.bind(
# "bool" is not assignable to "str"
-argument("IP", type=bool),
# Type "bool | None" is not assignable to type "bool"
until_stopped=-flag("-t", default=None),
#
# Argument missing for parameter "count"
)
IDE suggestions work too:
cli.bind(⏎
(addr: str, *, until_stopped: bool, count: int | None) -> None
Installation
pip install paramspecli
Key points
paramspecli builds hierarchical CLIs with groups and commands.
- Commands match handler functions parameters with arguments and options.
- Arguments are bound to the handler's positional parameters.
- Options are bound to the handler's keyword parameters.
- Groups organize the commands. Groups may be nested. They could act like an intermediate commands, i.e. have own handlers, options and arguments.
- CLI 'compiles' to the
argparse, runs it, then outputs the parse result. - Parse result is a callable. Calling it invokes handlers along the route.
paramspecli supports several advanced argparse features: help sections, mutually exclusive
options, options with the same destination. And adds a few own, like const options and passing contexts. It also includes a markdown documentation generator.
Metadata
Release files for paramspecli 0.3.1
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 |
|---|---|---|---|---|
| paramspecli-0.3.1.tar.gz | 23.4 kB | Without provenance | Details for paramspecli-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| paramspecli-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for paramspecli-0.3.1-py3-none-any.whl |
Total release size: 49.8 kB
Release files / paramspecli-0.3.1.tar.gz
| Download URL | paramspecli-0.3.1.tar.gz |
|---|---|
| Size | 23.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30c00cf7bc8b5369fbda29cbc6e6994520612f0fffcd99bd59525b2cff163103
|
|
BLAKE2b-256 checksum How to use checksums |
2d042c528392d546c592652cce6b2b51628e57bdbc9b36eaf139eee67df86323
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Release files / paramspecli-0.3.1-py3-none-any.whl
| Download URL | paramspecli-0.3.1-py3-none-any.whl |
|---|---|
| Size | 26.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
53325fcc6d50b48e9b8c248197c81439451c23b293005bcab69770ec55121198
|
|
BLAKE2b-256 checksum How to use checksums |
f3303c7f5630cea9b4aa18a780edbaefacbba98d48a9efcd3cd7f701029049da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Security for paramspecli 0.3.1
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.