Skip to main content

Argument clinic makes creates a command line interface out of your main() so you don't have to.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

argument-clinic-0.11.tar.gz (3.9 kB view details)

Uploaded Source

File details

Details for the file argument-clinic-0.11.tar.gz.

File metadata

  • Download URL: argument-clinic-0.11.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for argument-clinic-0.11.tar.gz
Algorithm Hash digest
SHA256 fe3e606162c3a4aff372f6f1c2dd84f74b82c8616088409a61b87c642a40ea7a
MD5 1c5e7791c224cd0bd708c51c080fb15a
BLAKE2b-256 8e3e8f65fec72d2621b5a02b1f206d46cd2e7d7e622a7a32119e1541a1714e0a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page