Skip to main content

Clak

Clak Logo

Python Version License PyPI

Clak (Command Line avec Klass) is a Python library for building command-line interfaces with a class-based API on top of standard argparse. Nested commands, arguments, and optional batteries (views, logging, config, completion) stay close to what you already know from the stdlib.

Full docs: mrjk.github.io/python-clak · PyPI: mrjk.clak

Features

  • Class-based CLI — define apps with Parser, Argument, and Command; no new DSL
  • Argparse-native — same argument syntax as add_argument() / subparsers
  • Nested commands — git-like trees with inheritance and a command overview in --help
  • Optional components — views, logging, XDG config, shell-completion script generation
  • Light core; extras only when you need them (colors, config)

Requirements

  • Python 3.10–3.14 (declared >=3.10,<4.0; CI and local matrix cover 3.10–3.14)
  • argparse (stdlib)

Developer setup and the version matrix: Development setup.

Install

pip install mrjk.clak

# Or with your project manager
poetry add mrjk.clak
pdm add mrjk.clak
uv add mrjk.clak

Optional:

pip install 'mrjk.clak[colors]'   # coloredlogs for LoggingOptMixin
pip install 'mrjk.clak[config]'   # PyYAML for YAML config / --format yaml

Quick start

from clak import Argument, Command, Parser


class ShowCommand(Parser):
    """Show something."""

    target = Argument("--target", "-t", help="Target to show")
    format = Argument(
        "--format", choices=["json", "text"], help="Output format"
    )

    def cli_run(self, target=None, format=None, **_):
        print(f"show target={target} format={format}")


class MainApp(Parser):
    """Demo application."""

    debug = Argument("--debug", action="store_true", help="Enable debug mode")
    config = Argument("--config", "-c", help="Config file path")

    show = Command(ShowCommand, help="Show something")


# Instantiating the root parser parses argv and runs the matching command.
if __name__ == "__main__":
    MainApp()
$ python demo.py --help
usage: demo.py [-h] [--debug] [--config CONFIG] {show} ...

Key concepts

Arguments

class MyCommand(Parser):
    verbose = Argument("-v", "--verbose", action="store_true", help="Verbose")

Nested commands

Command binds a child Parser (aliases: SubParser, SubCommand, Cmd):

class MainApp(Parser):
    status = Command(StatusCommand, help="Show status")

Optional components

Component Mixin / class Docs
Tables / structured output ListViewMixin, ShowViewMixin, PprintViewMixin Views
Logging + -v LoggingOptMixin Logging
XDG paths + config file XDGConfigMixin Config
Shell completion scripts CompCmdRender Completion

Learn more

Contributing

Bug reports, questions, and PRs are welcome. See the contribution guidelines in the documentation (or CONTRIBUTING.md).

License

GPL v3.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mrjk_clak-0.5.0.tar.gz (53.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mrjk_clak-0.5.0-py3-none-any.whl (60.7 kB view details)

Uploaded Python 3

File details

Details for the file mrjk_clak-0.5.0.tar.gz.

File metadata

  • Download URL: mrjk_clak-0.5.0.tar.gz
  • Upload date:
  • Size: 53.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.3 Linux/6.17.0-1020-azure

File hashes

Hashes for mrjk_clak-0.5.0.tar.gz
Algorithm Hash digest
SHA256 f0383df77db34f370bb71c5b914f1eb4e05b295b3b9d48f6ea7aafe0b75b59d7
MD5 b2cd30c369e97a0789bad3299b1dd90e
BLAKE2b-256 dc533c14b829636d0731763c24207968e929cfea5dad92dcbf5099949384cdec

See more details on using hashes here.

File details

Details for the file mrjk_clak-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: mrjk_clak-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 60.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.3 Linux/6.17.0-1020-azure

File hashes

Hashes for mrjk_clak-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12cd98fd3af8aa37cd810cb3d0218398f281a20133f7b52337c8f9196fa8f079
MD5 4e32b9b3ae13eb084fdef8fcaf1f61ef
BLAKE2b-256 32952f4503ca485e9ade65b87313e1c167f385246456909a0cc191e3691f7085

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.1

2 files

0.6.0

2 files

This release

0.5.0 This release

2 files

0.3.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page