Argument Clinic
Ah. I'd like to have an argument, please.
The standard way of writing a command line tool in Python is rather
repetitive. You construct an ArgumentParser object with a doc
string add documented parameters with their type, call parse on
it and then call your main(...) with exactly the same parameters
and if you are a good citizen, you document the call stuff again.
def main(input_file : str, *, scale : float = 125, fps : int = 30):
"""Create a movie based that has droste aspects."""
pass
if __name__ == '__main__':
parser = argparse.ArgumentParser('Create a movie based that has droste aspects.')
parser.add_argument('input_file', type=str)
parser.add_argument('--scale', type=float, default=125)
parser.add_argument('--fps', type=float, default=30)
args = parser.parse_args()
main(args.input, scale=args.scale, fps=args.fps)
With argument-clinic you can do the same with just:
@argument.entrypoint
def main(input_file : str, *, scale : float = 125, fps : int = 30):
"""Create a movie based that has droste aspects."""
pass
if __name__ == '__main__':
main()
Installation
pip install argument-clinic
More details
As shown above, the basic usage is to use the @argument.entrypoint
for your main and have all command line arguments to your script be
arguments of your main(..) entry point. When you call main the values
for each argument will be supplied automatically.
Separate positional arguments and keyword arguments in your
main with a * (which is good practice anyway). Anything after
the star becomes a flag that requires a value.
The doc string of your main will automatically become the help
for your script. If you document the parameters to your main in your
doc string, these comments will be added to the right parameters (any type
specification will be ignored though)
The best thing: it doesn't cost you 5 pounds for 5 more minutes.
Metadata
Release files for argument-clinic 0.12
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 | |
|---|---|---|---|---|
| argument-clinic-0.12.tar.gz | 3.9 kB | Without provenance | Details |
Release files / argument-clinic-0.12.tar.gz
| Download URL | argument-clinic-0.12.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b60d2c82f505f1856b3566cdca760b5958d254291f6f381f57ab01cf93d800d6
|
|
BLAKE2b-256 checksum How to use checksums |
756b4a8b8318fdad8415d8411e7c1abaa94041eb210115caa2a7cf04e898d4fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
|
Security for argument-clinic 0.12
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.