All posts

Build a Python CLI quickly with targ

Building command line tools is a daily occurrence for many developers, and is also an accessible way for junior programmers to build useful tools, without having to create a GUI.

I wanted to make a library which made building a command line tool as painless as possible. There are also some advanced features I needed from a CLI library for Piccolo, and so targ was born.

Targ creates a CLI just using type annotations and docstrings, so you can turn your existing functions into a CLI with very little effort.

from targ import CLI

def add(a: int, b: int):
    Add the two numbers.

    :param a:
        The first number.
    :param b:
        The second number.
    print(a + b)

if __name__ == "__main__":
    cli = CLI()

And from the command line:

>>> python add 1 1

To get documentation:

>>> python add --help

Add the two numbers.

add a b

The first number.

The second number.

I encourage you to give it a try.

More advanced features are coming soon.

Posted on: 22 Apr 2020

Have any comments or feedback on this post? Chat with us on GitHub.