Skip to content

Getting Started

Installation

Install Clantic using pip:

pip install clantic

Basic Usage

1. Define Parameters

First, define your command parameters using a Pydantic model:

from pydantic import BaseModel
from clantic.types import Argument, Option


class GreetParams(BaseModel):
    name: Argument[str]  # required argument
    greeting: Option[str] = "Hello"  # optional with default

2. Create Command

Create a command by inheriting from BaseCommand:

from clantic import BaseCommand


class GreetCommand(BaseCommand[GreetParams]):
    NAME = "greet"

    def run(self) -> None:
        print(f"{self.params.greeting}, {self.params.name}!")

3. Create CLI Group

Group your commands and create the CLI:

from clantic import Group

cli = Group()
cli.add_command_cls(GreetCommand)

if __name__ == "__main__":
    cli()

4. Run the CLI

Your CLI is now ready to use:

$ python my_cli.py greet --name Alice --greeting Hi
Hi, Alice!

Next Steps