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.12.tar.gz (3.9 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: argument-clinic-0.12.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.12.tar.gz
Algorithm Hash digest
SHA256 b60d2c82f505f1856b3566cdca760b5958d254291f6f381f57ab01cf93d800d6
MD5 037eba3c6f4d7912597836bb16bd3184
BLAKE2b-256 756b4a8b8318fdad8415d8411e7c1abaa94041eb210115caa2a7cf04e898d4fb

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