aarghparse
Motivation
I was having shower and this name came up.
At the moment this is a collection of argparse extensions I have written and found useful in recent times.
Features
@arg_converter decorator to write simple argument value parsers without the argparse.Action boilerplate
@subcommand decorator to save you from all the add_subparsers and set_defaults(func=).
@cli decorator to generate a command-line interface.
Example
The example below combines all the features, but the tool doesn’t enforce it on you.
If you have an existing argparse.ArgumentParser definition, you should be able to replace it with aarghparse by just changing the initialisation line to parser = aarghparse.ArgumentParser(...).
import datetime as dt
import dateutil.tz
from aarghparse import ArgumentParser, arg_converter, cli
@cli
def calendar_cli(parser: ArgumentParser, subcommand: ArgumentParser.subcommand):
"""
Command-line calendar.
"""
parser.add_argument(
'--date-format',
default=None,
)
@arg_converter
def tz_arg(value):
return dateutil.tz.gettz(value)
@subcommand(
name="now",
args=[
["--tz", {
"action": tz_arg,
"help": "Timezone",
}],
],
)
def now_cmd(args):
"""
Prints today's date.
"""
date_format = args.date_format or "%Y-%m-%d %H:%M:%S"
print(dt.datetime.now(tz=args.tz).strftime(date_format))
if __name__ == "__main__":
calendar_cli.run()
If you install python-dateutil then you can try the above with:
python -m aarghparse.examples.calendar --help
python -m aarghparse.examples.calendar now --help
python -m aarghparse.examples.calendar now --tz "Europe/Riga"
python -m aarghparse.examples.calendar --date-format "%d.%m.%Y." now --tz "Europe/Riga"
Metadata
Release files for aarghparse 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 |
|---|---|---|---|---|
| aarghparse-0.2.0.tar.gz | 4.7 kB | Without provenance | Details for aarghparse-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aarghparse-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for aarghparse-0.2.0-py3-none-any.whl |
Total release size: 10.3 kB
Release files / aarghparse-0.2.0.tar.gz
| Download URL | aarghparse-0.2.0.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
500e14ee131e5c713ea077d1821dbf6b1bc74857425707441f2374a4fefd1dd9
|
|
BLAKE2b-256 checksum How to use checksums |
f7104f81202a97aa1b914fb888137148ceb52d787ccc3553fa765c3936efa2b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|
Release files / aarghparse-0.2.0-py3-none-any.whl
| Download URL | aarghparse-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
09d8134c7f75639ed20038f991bbbff70982cbef774192a9a035cb28da6641b1
|
|
BLAKE2b-256 checksum How to use checksums |
a2d6d187093a80372b9224a8c67a9226e030c366d2e668692614f43c7e93d02f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|
Security for aarghparse 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.