Skip to main content

👀📎 Clippy

PyPI Version Python Versions Travis Build Status Codacy Badge MIT codecov

Clippy (Command Line Interface Parser for Python) crawls the abstract syntax tree (AST) of a Python file and generates a simple command-line interface.

Installation

Clippy is available in PyPI and can be installed via pip.

pip install Clippy

Clippy requires Python 3.6. There is no plan to support Python 2 at this time, but earlier versions of Python 3 may be included in the future.

Usage

All functions that you would like to be available as commands should be annotated with @clippy. You can then call begin_clippy(), in, for example, the main block of your module.

"""
This is a Python module.
"""

from clippy import clippy, begin_clippy


@clippy
def some_function(foo: int, bar: str = "optional") -> str:
    """
    This is some function.

    :param foo: The first parameter.
    :param bar: The second parameter.
    :returns: The result of the function.
    """
    return f"some_value {foo} {bar}"


if __name__ == "__main__":
    begin_clippy()

When you call this file from the command line as follows:

python -m examples.readme

You will now receive information about the annotated method. This information is all based on the docstrings and annotations you've already provided in your code.

This is a Python module.

Usage:
	python -m examples.readme some_function <foo> [--bar=<str>] 
	python -m examples.readme --help

Options:
	--help   Show this screen.
	--bar    The second parameter.

Each command can then provide additional help information as needed.

python -m examples.readme some_function --help

Which results in the following output:

This is some function.

Usage:
	python -m examples.readme some_function <foo> [--bar=<str>] 

Positional arguments:
	foo      The first parameter.

Options:
	--help   Show this screen.
	--bar    The second parameter.

Note that any parameter that has a default value is treated as an option requiring a label with the -- prefix. Required parameters are treated as positional arguments. The goal is to closely match the docopt specification.

Functions that are missing documentation or type annotations will use default or placeholder values. Essentially, any valid Python function will be parsed and available on the command line.

Why Clippy

There are a number of comparable Python packages available. Clippy is designed specifically to make your existing module functions available on the command line with little effort, without modifying the way these functions behave currently.

If you'd like to create more comprehensive tools specifically for the command line, check out Click. If you'd like to make scripts with extensive customization of command-line flags, try argparse. If you'd like to parse or verify existing documentation, try docopt.

Todo

  • Use hypothesis to improve tests
  • Send output of examples to docopt to verify formatting
  • Support different parameter formatting, e.g. @param vs. :param
  • Generate, validate, and upload docs
  • Support nested commands, e.g. python -m my_module parent_method child_method
  • Support Python 3.5
  • Improved handling for list type command-line arguments
  • Lazily evaluate methods to improve performance (often only one method needs parsed)

License

All content in this repository is shared under an MIT license. See license.md for details.

Metadata

Release files for Clippy 0.6.4

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

Source distribution (sdist)

Source distribution for Clippy 0.6.4
File Size Uploaded
Clippy-0.6.4.tar.gz 12.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Clippy 0.6.4
File Interpreter ABI Platform
Clippy-0.6.4-py3-none-any.whl Python 3 none any Details

Total release size: 28.9 kB

Release files / Clippy-0.6.4.tar.gz

Download URL Clippy-0.6.4.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2491cb34cd3fd394f1d7664a6db3efb4f48297cf0201afc84319b915746d3e09
BLAKE2b-256 checksum
How to use checksums
3b649d16ffef72e9617e1922dc39b5332f97fc57231072f8d9cea762b2245890
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release files / Clippy-0.6.4-py3-none-any.whl

Download URL Clippy-0.6.4-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f26028c837a9347e8f8512ce9636a4a2ba8d993b1b36cfdb3582fee8ee680753
BLAKE2b-256 checksum
How to use checksums
91cf8c2a482bc1b66d342f1603c0a1340e47ad56b8e90fed2a61b04d52cbd427
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.6.4 This release

2 release files

0.6.3

2 release files

0.5.1

2 release files

0.5.0

2 release files

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