Intuitive, easy CLIs based on type hints.
npx @tessl/cli install tessl/pypi-cyclopts@3.23.0Cyclopts is a modern, intuitive command-line interface (CLI) framework for Python that provides an efficient developer experience through advanced type hinting support, automatic help generation from docstrings, and extensible customization options. The library enables developers to quickly create CLI applications using a terse, intuitive syntax that fully supports all builtin Python types and user-specified types including Pydantic models, dataclasses, and Attrs.
pip install cycloptsimport cycloptsCommon patterns for building CLI applications:
from cyclopts import App, run
from cyclopts import Parameter, ArgumentFor configuration and advanced features:
from cyclopts import config, types, validators
from cyclopts import Group, Tokenfrom cyclopts import run
def hello(name: str, count: int = 1):
"""Say hello to someone.
Parameters
----------
name
The name to greet
count
Number of times to greet
"""
for _ in range(count):
print(f"Hello {name}!")
if __name__ == "__main__":
run(hello)from cyclopts import App
app = App()
@app.command
def add(x: int, y: int):
"""Add two numbers."""
print(x + y)
@app.default
def main():
"""Main command when no subcommand specified."""
print("Use 'add' command to add numbers")
if __name__ == "__main__":
app()Cyclopts follows a modular architecture centered around these key components:
This design provides maximum flexibility while maintaining an intuitive API that leverages Python's type system for automatic CLI generation.
The foundation of Cyclopts CLI applications, providing the App class for command registration, argument parsing, and execution flow control.
class App:
def __init__(self, **kwargs): ...
def command(self, func: Callable = None, *, name: str = None) -> Callable: ...
def default(self, func: Callable = None) -> Callable: ...
def parse_args(self, tokens: list[str] = None) -> Any: ...
def __call__(self, tokens: list[str] = None) -> Any: ...
def run(func: Callable, **kwargs) -> Any: ...Fine-grained control over command-line argument behavior, validation, and presentation through Argument, Parameter, and related configuration classes.
class Argument:
def __init__(self, **kwargs): ...
class ArgumentCollection(list):
def __init__(self, *args): ...
class Parameter:
def __init__(self, **kwargs): ...Comprehensive type conversion system with pre-built validated types and custom validation support for robust CLI input handling.
def convert(type_, tokens: list[Token]) -> Any: ...
# Pre-built validated types from cyclopts.types
PositiveInt = Annotated[int, ...]
ExistingFile = Annotated[Path, ...]
Email = Annotated[str, ...]File-based configuration loading system supporting JSON, TOML, YAML formats and environment variable integration.
from cyclopts.config import Json, Toml, Yaml, Env
class Json:
def __init__(self, file: Path): ...
class Toml:
def __init__(self, file: Path): ...Extended functionality including interactive editing, token manipulation, custom dispatching, and help system customization.
def edit(text: str = "", **kwargs) -> str: ...
def env_var_split(value: str, type_: type) -> list[str]: ...
class Token:
keyword: str
value: str
source: strComprehensive exception hierarchy for precise error handling and debugging in CLI applications.
class CycloptsError(Exception): ...
class ValidationError(CycloptsError): ...
class MissingArgumentError(CycloptsError): ...