knack
A Command-Line Interface framework
What it is and what it does
Knack is a framework for building structured command-line interfaces in Python. It handles command registration, argument parsing, help text generation, and output formatting so you can focus on implementing command logic rather than CLI plumbing. The framework uses a loader pattern where you define command groups and arguments declaratively, then invoke the CLI with user input to execute the appropriate command.
The package depends on argcomplete for shell completion, jmespath for output filtering, packaging for version handling, pygments for syntax highlighting, pyyaml for configuration, and tabulate for formatted output. It's designed to scale from simple single-command tools to complex multi-command CLIs like the Azure CLI and VSTS CLI, which use knack in production. The project is in active development and maintained, though the authors recommend pinning to a specific minor version rather than using loose version constraints.
Use it for:
- Build a multi-command CLI tool with subcommands, argument validation, and automatic help text generation.
- Create a wrapper around Azure or cloud service APIs that exposes functionality through a structured command interface.
- Develop an internal DevOps or automation tool with consistent argument parsing and formatted output across many commands.
- Add shell completion and formatted table output to an existing command-line application.
- Implement a CLI that reads YAML or JSON configuration and applies it through structured commands.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Knack is a Python framework for building command-line interfaces with argument parsing, command organization, and output formatting built in.
Yes, if you are building a command-line tool in Python and want to avoid writing boilerplate argument parsing and command dispatch logic. The framework is actively maintained, has low install friction, and is proven in production by major projects like Azure CLI. Pin to a specific minor version as the authors recommend, since the project is still in initial development phase.
Install
knack on PyPI
pip
pip install knackuv
uv add knackpoetry
poetry add knackInstalling knack
Before you install
Low install friction with six common runtime dependencies. The project is actively maintained with a recent release, though the maintainers note it remains in initial development phase and recommend pinning to a specific minor version when used as a dependency.
License in practice
MIT license is permissive; you can use, modify, and distribute knack with minimal restrictions, though you must include the license notice.
Quickstart
pip install knack
from knack import CLI, CLICommandsLoader
from knack.commands import CommandGroup
class MyCommandsLoader(CLICommandsLoader):
def load_command_table(self, args):
with CommandGroup(self, 'mygroup', '__main__#{}') as g:
g.command('mycommand', 'my_function')
return self.command_table
mycli = CLI(cli_name='mycli', commands_loader_cls=MyCommandsLoader)
exit_code = mycli.invoke(['mygroup', 'mycommand'])
Verify before relying
- Whether the framework supports subcommands, aliases, or command hierarchies beyond the basic group structure shown in examples.
- What testing or validation utilities knack provides for CLI applications built with it.
- Performance characteristics or scalability limits for CLIs with many commands or complex argument trees.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — argcomplete, jmespath, packaging, pygments, pyyaml, tabulate |
| Maintenance | actively maintained — 92 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 7,443,659/month — #1,738 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: knack-0.14.0-py3-none-any.whl
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
ms-fabric-cliA command-line interface for Microsoft Fabric…
unclear · top 15,000 on PyPI
azure-cli-coreProvides the core Python library and CLI…
permissive · top 5,000 on PyPI
sfctlA command-line interface for managing Azure…
permissive · top 15,000 on PyPI
botbuilder-coreProvides the core SDK for building bots that…
permissive · top 5,000 on PyPI
cliffcliff is a framework for building command-line…
permissive · top 5,000 on PyPI
az.cliExecutes Azure CLI commands from Python and…
permissive · top 15,000 on PyPI
azdevazdev is a command-line tool that helps…
permissive · top 15,000 on PyPI
clikitCliKit provides utilities for building…
permissive · top 5,000 on PyPI
argsParses command-line arguments into categorized…
permissive · top 15,000 on PyPI