Skip to main content

argparse_decoration

A argparse wrapper through decorations

30 sec tutorial

Given test.py with:

#!/bin/python3

from argparse_decorations import init, Command, parse_and_run

init()

@Command('mycommand')
def handler():
    print('Hello!')

parse_and_run()

then ./test.py produces:

usage: test.py [-h] {mycommand} ...

Help message

positional arguments:
  {mycommand}

options:
  -h, --help   show this help message and exit

and ./test.py mycommand:

Hello!

1 min tutorial

The program:

from argparse_decorations import init, Command, SubCommand, Argument, parse_and_run

init()

@Command('mycommand')
@SubCommand('add')
@Argument('a', type=int)
@Argument('b', type=int)
def add_handler_but_could_be_any_identifier(a, b):
    print(a + b)

parse_and_run()

when called ./test.py mycommand add 1 2 produces:

3

@Command and @SubCommand will make a call to ArgumentParser.add_parser() and @Argument will call ArgumentParser.add_argument These calls are made 'as-is' passing every *args and **kwargs passed on decorations to commands

A complete example whose explore all possibilities:

@Command('math')
@SubCommand('add')
@Argument('valueA', type=int)
@Argument('valueB', type=int)
def add_handler(valueA, valueB):
    print('Adding args ' + str(valueA) + ' and ' + str(valueB))
    print(valueA + valueB)


@Command('math')
@SubCommand('sub')
@Argument('valueA', type=int)
@Argument('valueB', type=int)
def subtract_handler(valueA, valueB):
    print('Subtracting args ' + str(valueA) + ' and ' + str(valueB))
    print(valueA - valueB)


@Command('math')
@SubCommand('mul')
@Argument('valueA', type=int)
@Argument('valueB', type=int)
def subtract_handler(valueA, valueB):
    print('Multiplying args ' + str(valueA) + ' and ' + str(valueB))
    print(valueA * valueB)


@Command('math')
@SubCommand('pi')
def pi():
    print('3.1415926535979')

Metadata

Release files for argparse-decorations 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for argparse-decorations 1.1.0
File Size Uploaded Provenance Actions
argparse_decorations-1.1.0.tar.gz 6.6 kB Without provenance Details for argparse_decorations-1.1.0.tar.gz

Release files / argparse_decorations-1.1.0.tar.gz

Download URL argparse_decorations-1.1.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
551f3b812dfa45f1e19487f1894bc25cd382e6315adb402b4d3baad617a5d9b0
BLAKE2b-256 checksum
How to use checksums
7014e770a8bd0d329047387a8fda79fe20d32132fc55b0e1939dee26c6e6b14b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for argparse-decorations 1.1.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page