clapy-derive
A clap-inspired declarative CLI argument parser for Python.
Define your CLI as a plain class with type annotations — clapy-derive handles parsing, help generation, and type conversion.
from clapy_derive import clapy_arg, clapy_parser
@clapy_parser("version", "verbose")
class Cli:
"""My awesome tool."""
input: str = clapy_arg(short=True, long=True, help="input file")
output: str = clapy_arg(short=True, long=True, default="output.txt")
if __name__ == "__main__":
cli = Cli.parse()
print(cli.input)
print(cli.output)
$ python main.py --input data.csv
data.csv
output.txt
$ python main.py -i data.csv -o result.txt
data.csv
result.txt
$ python main.py --help
usage: cli [-h] [-V] [-v] -i INPUT [-o OUTPUT]
My awesome tool.
options:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-v, --verbose Enable verbose output
-i, --input INPUT input file
-o, --output OUTPUT
Installation
pip install clapy-derive
Usage
Positional arguments
A field with no clapy_arg() becomes a required positional argument — the same as clap's default behaviour for bare struct fields.
@clapy_parser()
class Cli:
name: str # positional, required
greeting: str = "hello" # positional, optional with default
$ python main.py alice
Named flags (--long / -s)
Use clapy_arg(short=True, long=True) to add -x / --xxx flags.
@clapy_parser()
class Cli:
output: str = clapy_arg(short=True, long=True, default="out.txt")
count: int = clapy_arg(short=True, long=True, default=1)
short=True— auto-assign the first character of the field name (-o,-c)long=True— use the field name as the long flag (--output,--count)- Pass an explicit string to override:
short="O",long="out"
Underscores in field names are converted to hyphens on the CLI (output_file → --output-file).
Optional values (T | None)
Annotate with T | None to make an argument optional. The value is None when not provided.
@clapy_parser()
class Cli:
config: str | None = clapy_arg(short=True, long=True)
$ python main.py # cli.config is None
$ python main.py -c x # cli.config == "x"
Multiple values (list[T])
Annotate with list[T] to accept one or more values.
@clapy_parser()
class Cli:
files: list[str] = clapy_arg(short=True, long=True)
$ python main.py --files a.txt b.txt c.txt
Boolean flags
A bool field becomes a store-true flag (default False).
@clapy_parser()
class Cli:
debug: bool = clapy_arg(short=True, long=True)
$ python main.py --debug # cli.debug is True
$ python main.py # cli.debug is False
Built-in flags
Pass strings to @clapy_parser() to enable built-in flags:
| String | Flags added |
|---|---|
"version" |
-V / --version (reads version from package metadata) |
"verbose" |
-v / --verbose (sets cli.verbose: bool) |
@clapy_parser("version", "verbose")
class Cli:
...
Type conversion
clapy-derive infers the conversion type from the field annotation automatically.
| Annotation | CLI input | Python value |
|---|---|---|
str |
"hello" |
"hello" |
int |
"42" |
42 |
float |
"3.14" |
3.14 |
pathlib.Path |
"/tmp/f" |
Path("/tmp/f") |
bool |
flag present | True |
clapy_arg() reference
| Parameter | Type | Default | Description |
|---|---|---|---|
short |
bool | str |
False |
-x flag. True = first char of field name |
long |
bool | str |
True |
--xxx flag. True = field name |
help |
str |
"" |
Help text shown in --help |
default |
Any |
(required) | Default value; makes the argument optional |
choices |
list | None |
None |
Restrict to a set of allowed values |
metavar |
str | None |
None |
Placeholder name in help output |
env |
str | None |
None |
Environment variable to fall back to |
Requirements
- Python 3.12+
License
MIT
Metadata
Release files for clapy-derive 0.2.0
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 |
|---|---|---|---|---|
| clapy_derive-0.2.0.tar.gz | 5.6 kB | Without provenance | Details for clapy_derive-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| clapy_derive-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for clapy_derive-0.2.0-py3-none-any.whl |
Total release size: 12.9 kB
Release files / clapy_derive-0.2.0.tar.gz
| Download URL | clapy_derive-0.2.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c075c1a19182169915fe3489061f8aa22f509b2936b70e141261e8458be8dbd8
|
|
BLAKE2b-256 checksum How to use checksums |
327d1dd220e68c5298fc5bbf1475d39e46ee44b71e517562ee0b4984b114c467
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / clapy_derive-0.2.0-py3-none-any.whl
| Download URL | clapy_derive-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
299463890e578b57e70fe0ee819758888b799b4195ec8f1df22d31e9ba2cc47e
|
|
BLAKE2b-256 checksum How to use checksums |
c78221dd389419360788b727fe4741cdfd685df49c556e802ec2af6bbec53f1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for clapy-derive 0.2.0
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.