chi-sdk

Build beautiful Terminal UIs for Python CLIs without rewriting your code


Licenses
Apache-2.0/Afmparse
Install
pip install chi-sdk==0.0.5

Documentation

CHI SDK - Beautiful TUIs for Python CLIs

CI PyPI - Version License

Add a beautiful Terminal UI to your Python CLI with just a few decorators. No need to learn a new framework or rewrite your logic.

Why CHI SDK?

You've built a Python CLI with Click or argparse. Now you want a nice TUI but:

  • Other TUI frameworks require rewriting your entire application
  • You don't want to maintain two separate codebases
  • You need your CLI to work both in scripts (CLI mode) and interactively (TUI mode)

CHI SDK solves this: Keep your existing CLI, add a few decorators, get a beautiful TUI.

Quick Start

1. Install

pip install chi-sdk

That's it! TUI included, batteries included.

2. Add to Your CLI

from chi_sdk import chi_command, build_cli
from pydantic import BaseModel

class GreetingInput(BaseModel):
    name: str
    
class GreetingOutput(BaseModel):
    message: str

@chi_command(input_model=GreetingInput, output_model=GreetingOutput)
def greet(inp: GreetingInput) -> GreetingOutput:
    return GreetingOutput(message=f"Hello, {inp.name}!")

# Build your CLI with all registered commands
cli = build_cli("your-app")

if __name__ == "__main__":
    cli()

3. Run Your TUI

# Just add 'ui' to your command!
your-app ui

That's it! Every CHI SDK app automatically gets a ui subcommand.

Features

Automatic TUI - Every app gets a ui subcommand, no config needed
Zero Learning Curve - Use your existing Python knowledge
Type Safety - Pydantic models ensure correctness
Dual Mode - Same code works as CLI and TUI
JSON Contract - Stable interface for automation
Progress Tracking - Built-in support for long-running tasks
Fast & Responsive - Native performance (Rust-powered TUI under the hood)

Real Example

See the example-apps/ directory for complete examples:

# Install example app
pip install -e example-apps/example-app

# Run as CLI
example-app hello --name World

# Run as TUI - just add 'ui'!
example-app ui

# Get JSON output for automation
example-app --json list-items

Customizing Your TUI

While your-app ui works out of the box, you can customize the interface:

# Generate TUI configuration templates
chi-admin init . --binary-name=your-app

# This creates:
# .tui/main.yaml      - Menu structure and navigation
# .tui/panel_b.yaml   - Panel layouts configuration  
# .tui/styles.yaml    - Colors and visual styling
# .tui/bin/your-app-ui - Standalone launcher (optional)

Edit the YAML files to:

  • Customize menu items and structure
  • Define keyboard shortcuts
  • Change colors and styling
  • Configure panel layouts

The YAML files include helpful comments explaining each option.

How It Works

  1. You write Python CLI commands with Pydantic models for input/output
  2. CHI SDK generates a JSON schema describing your commands
  3. The TUI reads this schema and creates a beautiful interface
  4. User interactions in TUI call your CLI commands behind the scenes
  5. Your CLI returns JSON which the TUI displays nicely

Your Python code remains the single source of truth. The TUI is just a presentation layer.

Documentation

Development

# Setup development environment
python -m venv .venv
source .venv/bin/activate
pip install -r requirements-dev.txt
pip install -e python-chi-sdk

# Run tests
pytest python-chi-sdk/tests

# Run linting
ruff check .
black .

License

  • Python SDK: Apache 2.0 - Use freely in commercial projects
  • TUI Binary: AGPL 3.0 - Keep open source or contact us for commercial license

See LICENSE for details.

Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Support