{"id":26844965,"url":"https://github.com/moigagoo/cliar","last_synced_at":"2025-04-30T20:23:48.340Z","repository":{"id":62562587,"uuid":"134086512","full_name":"moigagoo/cliar","owner":"moigagoo","description":"Create modular Python CLIs with type annotations and inheritance","archived":false,"fork":false,"pushed_at":"2022-12-08T12:49:51.000Z","size":1334,"stargazers_count":51,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-04-25T16:00:18.068Z","etag":null,"topics":["argparse","argparser","cli","click","command-line","commandline","commandline-interface","docopt","python"],"latest_commit_sha":null,"homepage":"https://moigagoo.nim.town/cliar/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moigagoo.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-19T18:07:15.000Z","updated_at":"2024-09-12T13:19:38.000Z","dependencies_parsed_at":"2023-01-25T13:15:37.717Z","dependency_job_id":null,"html_url":"https://github.com/moigagoo/cliar","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moigagoo%2Fcliar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moigagoo%2Fcliar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moigagoo%2Fcliar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moigagoo%2Fcliar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moigagoo","download_url":"https://codeload.github.com/moigagoo/cliar/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251775819,"owners_count":21641886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["argparse","argparser","cli","click","command-line","commandline","commandline-interface","docopt","python"],"created_at":"2025-03-30T19:33:57.675Z","updated_at":"2025-04-30T20:23:48.313Z","avatar_url":"https://github.com/moigagoo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![image](https://img.shields.io/pypi/v/cliar.svg)](https://pypi.org/project/cliar)\n[![Build Status](https://travis-ci.com/moigagoo/cliar.svg?branch=develop)](https://travis-ci.com/moigagoo/cliar)\n[![image](https://codecov.io/gh/moigagoo/cliar/branch/develop/graph/badge.svg)](https://codecov.io/gh/moigagoo/cliar)\n\n# Cliar\n\n**Cliar** is a Python package to help you create commandline interfaces. It focuses on simplicity and extensibility:\n\n-   Creating a CLI is as simple as subclassing from `cliar.Cliar`.\n-   Extending a CLI is as simple as subclassing from a `cliar.Cliar` subclass.\n\nCliar'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.\n\n\n## Installation\n\n```shell\n$ pip install cliar\n```\n\nCliar requires Python 3.6+ and is tested on Windows, Linux, and macOS. There are no dependencies outside Python's standard library.\n\n\n## Basic Usage\n\nLet's create a commandline calculator that adds two floats:\n\n```python\nfrom cliar import Cliar\n\n\nclass Calculator(Cliar):\n    '''Calculator app.'''\n\n    def add(self, x: float, y: float):\n        '''Add two numbers.'''\n\n        print(f'The sum of {x} and {y} is {x+y}.')\n\n\nif __name__ == '__main__':\n    Calculator().parse()\n```\n\nSave this code to `calc.py` and run it. Try different inputs:\n\n-   Valid input:\n\n        $ python calc.py add 12 34\n        The sum of 12.0 and 34.0 is 46.0.\n\n-   Invalid input:\n\n        $ python calc.py add foo bar\n        usage: calc.py add [-h] x y\n        calc.py add: error: argument x: invalid float value: 'foo'\n\n-   Help:\n\n        $ python calc.py -h\n        usage: calc.py [-h] {add} ...\n\n        Calculator app.\n\n        optional arguments:\n        -h, --help  show this help message and exit\n\n        commands:\n        {add}       Available commands:\n            add       Add two numbers.\n\n-   Help for `add` command:\n\n        $ python calc.py add -h\n        usage: calc.py add [-h] x y\n\n        Add two numbers.\n\n        positional arguments:\n        x\n        y\n\n        optional arguments:\n        -h, --help  show this help message and exit\n\nA few things to note:\n\n-   It's a regular Python class with a regular Python method. You don't need to learn any new syntax to use Cliar.\n\n-   `add` method is converted to `add` command, its positional params are converted to positional commandline args.\n\n-   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.\n\n-   `--help` and `-h` flags are added automatically and the help messages are generated from the docstrings.\n\n\n## Setuptools and Poetry\n\nTo invoke your CLI via an entrypoint, wrap `parse` call in a function and point to it in your `setup.py` or `pyproject.toml`.\n\n`calc.py`:\n\n    ...\n    def entry_point():\n        Calculator().parse()\n\n`setup.py`:\n\n    setup(\n        ...\n        entry_points = {\n            'console_scripts': ['calc=calc:entry_point'],\n        }\n        ...\n    )\n\n`pyproject.toml`:\n\n    ...\n    [tool.poetry.scripts]\n    calc = 'calc:entry_point'\n\n\n## Read Next\n\n-   [Tutorial →](https://moigagoo.github.io/cliar/tutorial/)\n-   [Cliar vs. Click vs. docopt →](https://moigagoo.github.io/cliar/comparison/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoigagoo%2Fcliar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoigagoo%2Fcliar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoigagoo%2Fcliar/lists"}