Skip to main content

Create CLIs with classes and type hints.

Project description

image Build Status image


Cliar is a Python package to help you create commandline interfaces. It focuses on simplicity and extensibility:

  • Creating a CLI is as simple as subclassing from cliar.Cliar.
  • Extending a CLI is as simple as subclassing from a cliar.Cliar subclass.

Cliar's mission is to let you focus on the business logic instead of building an interface for it. At the same time, Cliar doesn't want to stand in your way, so it provides the means to customize the generated CLI.


$ pip install cliar

Cliar requires Python 3.6+ and is tested on Windows, Linux, and macOS. There are no dependencies outside Python's standard library.

Basic Usage

Let's create a commandline calculator that adds two floats:

from cliar import Cliar

class Calculator(Cliar):
'''Calculator app.'''

    def add(self, x: float, y: float):
    '''Add two numbers.'''

        print(f'The sum of {x} and {y} is {x+y}.')

if __name__ == '__main__':

Save this code to and run it. Try different inputs:

  • Valid input:

    $ python add 12 34
    The sum of 12.0 and 34.0 is 46.0.
  • Invalid input:

    $ python add foo bar
    usage: add [-h] x y add: error: argument x: invalid float value: 'foo'
  • Help:

    $ python -h
    usage: [-h] {add} ...
    Calculator app.
    optional arguments:
    -h, --help  show this help message and exit
    {add}       Available commands:
        add       Add two numbers.
  • Help for add command:

    $ python add -h
    usage: add [-h] x y
    Add two numbers.
    positional arguments:
    optional arguments:
    -h, --help  show this help message and exit

A few things to note:

  • It's a regular Python class with a regular Python method. You don't need to learn any new syntax to use Cliar.

  • add method is converted to add command, its positional params are converted to positional commandline args.

  • There is no explicit conversion to float for x or y or error handling in the add method body. Instead, x and y are just treated as floats. Cliar converts the types using add's type hints. Invalid input doesn't even reach your code.

  • --help and -h flags are added automatically and the help messages are generated from the docstrings.

Read Next

Project details

Download files

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

Files for cliar, version 1.3.4
Filename, size File type Python version Upload date Hashes
Filename, size cliar-1.3.4-py3-none-any.whl (6.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size cliar-1.3.4.tar.gz (6.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page