The fastest, simplest way to create a CLI in Python
cli-buddy provides an ergonomic syntax for creating command-line interfaces in Python.
With cli-buddy, 👇 this code snippet is all it takes to build a CLI.
from cli_buddy import CLI
class MyCLI(CLI):
arg: str
Under the hood, cli-buddy is a pydantic-flavored wrapper around the built-in argparse module.
Requirements
- Python 3.11+
Install
pip install cli-buddy
Usage
Use the CLI class to define your CLI's arguments and options.
This code snippet...
# main.py
from cli_buddy import CLI
class TerminalTimer(CLI):
seconds: int
# boolean fields are automatically converted to flags
show_time: bool
... will produce the following CLI:
$ python main.py --help
usage: main.py [-h] seconds
positional arguments:
seconds
options:
-h, --help show this help message and exit
--show_time
A CLI class alone won't run anything, obviously. We need to define our behavior first.
Define your CLI's behavior
Either use your CLI instance however you like...
# main.py
...
cli = TerminalTimer()
for _ in range(cli.seconds):
print(_)
time.sleep(1)
... or just put your logic within the __call__() method of your CLI class...
class TerminalTimer(CLI):
seconds: int
show_time: bool
def __call__(self):
for _ in range(self.seconds):
print(_)
time.sleep(1)
TerminalTimer() # That's it!
Give your arguments default values to convert arguments to flags.
The CLI class will automatically convert arguments to flags if:
- they are assigned a default value,
- or if the field is a boolean.
For example, this...
class TerminalTimer(CLI):
seconds: int = 1
show_time: bool
... will produce the following CLI:
$ python main.py --help
usage: main.py [-h] [--seconds SECONDS] [--show_time]
options:
-h, --help show this help message and exit
--seconds SECONDS (default: 1)
--show_time
Use the Argument class to further configure your CLI's arguments.
The Argument function takes the same arguments as the built-in argparse.ArgumentParser.add_argument function.
For example, this...
from cli_buddy import CLI, Argument
class TerminalTimer(CLI):
seconds: int = Argument(help="Number of seconds to wait")
show_time: bool = Argument("-t", help="Show seconds in terminal", action="store_true")
... will produce the following CLI:
$ python main.py --help
usage: main.py [-h] -t seconds
positional arguments:
seconds Number of seconds to wait
options:
-h, --help show this help message and exit
-t, --show_time Show seconds in terminal
Metadata
Release files for cli-buddy 0.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cli_buddy-0.2.6.tar.gz | 5.5 kB | Without provenance | Details for cli_buddy-0.2.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cli_buddy-0.2.6-py3-none-any.whl | Python 3 | none | any | Details for cli_buddy-0.2.6-py3-none-any.whl |
Total release size: 12.8 kB
Release files / cli_buddy-0.2.6.tar.gz
| Download URL | cli_buddy-0.2.6.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a61882b15862a1783120bcd2d97444dec95408c7b63010e6b8d4efcae6f48979
|
|
BLAKE2b-256 checksum How to use checksums |
d45742adad3dedc1393f1a21c590d45570009ff6207f338e014183f4090b6d32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.11.1 Darwin/23.5.0
|
Release files / cli_buddy-0.2.6-py3-none-any.whl
| Download URL | cli_buddy-0.2.6-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
461fcf9b51b038fa84839588a7b54bc6bd782e66a31a8ebe8854b4495c7d6286
|
|
BLAKE2b-256 checksum How to use checksums |
fd22b24f698cc9b952695509484062f986b87cec77c4a9292e2c8dda37480ea4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.11.1 Darwin/23.5.0
|
Security for cli-buddy 0.2.6
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.