Skip to main content
# ClassCLI
Command Line Interfaces from class definitions.

[![PyPI version](https://badge.fury.io/py/classcli.svg)](https://badge.fury.io/py/classcli) [![PyPI version](https://img.shields.io/badge/python-%3E%3D%203.5-blue.svg)](https://pypi.org/project/classcli/) [![Build Status](https://travis-ci.org/Hrabal/ClassCLI.svg?branch=master)](https://travis-ci.org/Hrabal/ClassCLI) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/ece6dfe1a5774a5992061515b36db0d4)](https://app.codacy.com/app/federicocerchiari/ClassCLI?utm_source=github.com&utm_medium=referral&utm_content=Hrabal/ClassCLI&utm_campaign=Badge_Grade_Dashboard) [![Maintainability](https://api.codeclimate.com/v1/badges/d281ff92c2d45c4f2e75/maintainability)](https://codeclimate.com/github/Hrabal/ClassCLI/maintainability) [![Coverage Status](https://coveralls.io/repos/github/Hrabal/ClassCLI/badge.svg?branch=master)](https://coveralls.io/github/Hrabal/ClassCLI?branch=master) [![Downloads](https://pepy.tech/badge/classcli)](https://pepy.tech/project/classcli) [![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/Hrabal/ClassCLI/master/LICENSE)

Very similar to [Fire](https://github.com/google/python-fire), this is a Python module that let you build command line interfaces directly from collection of classes, saving you from writing boilerplate code.

ClassCLI is built on top of argparse, it create arguments of the cli by inspecting the classes in a given list or in a module. Each compatible class is transformed in a first-level argument, each function in a second-level argument, each function's argument in a third level argument.

ClassCLI uses docstrings to build the CLI's help, kwargs defaults to set CLI's pars defaults and type hints to infer CLI's pars types.

ClassCLI can be used to build CLI interfaces on top of existing APIs, or can be used to write scripts with a full-featured CLI writing commands and arguments as classes and functions.

Example code:
```python
from classcli import CliBuilder


class NonCommandClass:
pass


class MainCommand:
"""Docstring are used for help."""
callable_cls = True
command = 'foo'

def _base(self):
"""Docstring are used for help in methods too."""
print('This script is running as a foo.')

def with_args(self,
first_arg: int, # Type annotations are used to add a type check on the CLI arg
second_arg):
print('This script is running as a foo with %s %s.' % (first_arg, second_arg))


class SecondCommand:
callable_cls = True
command = 'bar'

def _base(self):
print('This script is running in a bar.')

def order(self,
order='Beer' # method kwargs are translated to optiona args in the form of "--arg"
):
print('You ordered a %s' % order)


if __name__ == '__main__':
CliBuilder(locals()).run_cli()

```


This projects's goals:
* this project should let fast CLI prototyping
* this project should stay lightweight

Metadata

Release files for classcli 0.0.2

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

Source distribution (sdist)

Source distribution for classcli 0.0.2
File Size Uploaded Provenance Actions
classcli-0.0.2.tar.gz 4.6 kB Without provenance Details for classcli-0.0.2.tar.gz

Release files / classcli-0.0.2.tar.gz

Download URL classcli-0.0.2.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e4c6a568ffc7e1036126a7220c37e29013b96b80d48fe08d9a36cec61f7f1798
BLAKE2b-256 checksum
How to use checksums
4ac1fbe28ccc3958449dc5fa23319f9f1a5685b8ce083960e71034d7faa8d792
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.19.1 CPython/3.6.4

Security for classcli 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file No provenance

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