A modern CLI toolkit for building beautiful terminal applications
Project description
Clir
A modern CLI toolkit for building beautiful terminal applications in Python.
Features
- Command Framework - Decorator-based command registration with type-annotated arguments
- Advanced Options - Repeatable options, fixed-arity options, and flag-to-parameter aliasing
- Rich Terminal Output - Colored text, tables, panels, progress bars, and spinners
- Interactive Prompts - Text input, confirmation dialogs, and selection prompts
- Type Inference - Automatically infer argument types from function signatures
- Async Support - Commands can be async functions
- Testing Utilities - Built-in tools for testing CLI applications
Installation
pip install pyclir
pyclir is the PyPI distribution name; the import package is clir
(import clir). The name clir was already taken on PyPI.
Quick Start
from clir import ClirApp, argument, option
from clir.output import success, error, Table
app = ClirApp(
name="mycli",
description="My awesome CLI",
)
@app.command()
@argument("name")
@option("--count", "-c", default=1)
def greet(name: str, count: int):
"""Greet someone warmly."""
for _ in range(count):
success(f"Hello, {name}!")
@app.command()
def status():
"""Show system status."""
t = Table("Component", "Status")
t.add_row("Database", "Connected")
t.add_row("API", "Running")
t.show()
if __name__ == "__main__":
app.run()
Advanced Options
@option supports repeatable options, fixed-arity options, and binding a flag
to a differently-named Python parameter.
from pathlib import Path
from clir import ClirApp, argument, option
app = ClirApp(name="mycli")
@app.command()
# Repeatable: pass --salvage more than once; values collect into a list.
@option("--salvage", multiple=True, default=None, help="Salvage file (repeatable)")
# Fixed-arity: --compare A B consumes exactly two values.
@option("--compare", nargs=2, default=None, help="Two models to compare")
# dest-aliasing: the CLI flag is --in, the function parameter is in_path.
@option("--in", dest="in_path", help="Input file")
# pathlib.Path is a supported type; the function receives a Path.
@option("--out", type=Path, default=None, help="Output path")
def run(salvage, compare, in_path, out):
# mycli run --salvage a.jsonl --salvage b.jsonl --compare m1 m2 --in data.txt
# salvage == ["a.jsonl", "b.jsonl"] (None when not passed)
# compare == ["m1", "m2"] (None when not passed)
# in_path == "data.txt"
...
multiple=True— the option may be passed repeatedly; every value is collected into a list. Usedefault=Noneto distinguish "not passed" from "passed empty".nargs=N— the option consumes exactlyNvalues at once; the bound value is anN-element list. Combine withmultiple=Truefor a list of fixed-length lists.dest="..."— binds the option (or argument) to a Python parameter whose name differs from the flag spelling — useful when the flag would be a Python keyword (--in,--class). Works on@argumenttoo.type=—str,int,float,bool, andpathlib.Pathare all supported; for list-valued options the type converts each element.
Output Functions
from clir.output import success, error, warning, info, debug, Table, Panel
success("Operation completed!") # Green bold
error("Something went wrong") # Red bold
warning("Be careful") # Yellow bold
info("Here's some info") # Cyan
debug("Debug message") # Dim
# Tables
t = Table("Name", "Age")
t.add_row("Alice", "30")
t.add_row("Bob", "25")
t.show()
# Panels
Panel("Content", title="My Panel").show()
Interactive Prompts
from clir.prompts import prompt, confirm, select
# Text input
name = prompt("What is your name?")
# Confirmation
if confirm("Continue?", default=True):
print("Continuing!")
# Selection
choice = select("Choose:", ["Option 1", "Option 2", "Option 3"])
Testing
from clir import ClirApp
from clir.testing import CliRunner
app = ClirApp(name="test")
@app.command()
def hello():
print("Hello!")
runner = CliRunner(app)
result = runner.invoke(["hello"])
assert result.exit_code == 0
assert "Hello" in result.output
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyclir-0.2.2.tar.gz.
File metadata
- Download URL: pyclir-0.2.2.tar.gz
- Upload date:
- Size: 64.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
674e7fe5ae6aac34320d44a7678726fa8a69021fef6669a0abf73bd0c0d14091
|
|
| MD5 |
e6da2350dfcadcfced7080643f84c83b
|
|
| BLAKE2b-256 |
f6cf95135ab3c8814c8d33c8c5c719a512d4e3724fc9980457a39f333bf95351
|
Provenance
The following attestation bundles were made for pyclir-0.2.2.tar.gz:
Publisher:
publish.yml on exec/clir
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyclir-0.2.2.tar.gz -
Subject digest:
674e7fe5ae6aac34320d44a7678726fa8a69021fef6669a0abf73bd0c0d14091 - Sigstore transparency entry: 1555417346
- Sigstore integration time:
-
Permalink:
exec/clir@da9d92a95a0d15dcd46b11143d3d3ac15d2cb5c8 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/exec
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@da9d92a95a0d15dcd46b11143d3d3ac15d2cb5c8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyclir-0.2.2-py3-none-any.whl.
File metadata
- Download URL: pyclir-0.2.2-py3-none-any.whl
- Upload date:
- Size: 63.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e87b6834215ae421a915e558dd5bbcfed095ae4e192fa4413dd7945ceff1c951
|
|
| MD5 |
75fc703b6f6b8f947a15ec5acb79a3e3
|
|
| BLAKE2b-256 |
6864775f7d634e3af19d8c4794c7641210fe4417dac0bcc6220434df3ae5019b
|
Provenance
The following attestation bundles were made for pyclir-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on exec/clir
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyclir-0.2.2-py3-none-any.whl -
Subject digest:
e87b6834215ae421a915e558dd5bbcfed095ae4e192fa4413dd7945ceff1c951 - Sigstore transparency entry: 1555417351
- Sigstore integration time:
-
Permalink:
exec/clir@da9d92a95a0d15dcd46b11143d3d3ac15d2cb5c8 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/exec
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@da9d92a95a0d15dcd46b11143d3d3ac15d2cb5c8 -
Trigger Event:
push
-
Statement type: