cmdkit
raw JSON → 2.7.7 verified Fri May 01 auth: no python
A command-line utility toolkit for Python, providing classes and functions for building CLI applications with subcommands, namespaces, configuration, logging, and auto-colorized help text. Current version is 2.7.7, supporting Python 3.9+. It follows a moderate release cadence with bugfixes and minor features.
pip install cmdkit Common errors
error AttributeError: module 'cmdkit' has no attribute 'Command' ↓
cause Installed an older version (<2.5?) or incorrect import path. Command was not always top-level.
fix
Upgrade cmdkit to the latest version (pip install --upgrade cmdkit) and use 'from cmdkit import Command'.
error TypeError: __init__() got an unexpected keyword argument 'name' ↓
cause Forgot to call super().__init__(name=name) in Command subclass.
fix
Ensure your Command subclass has: super().__init__(name=name).
error ModuleNotFoundError: No module named 'toml' ↓
cause After upgrading to cmdkit 2.7.6+, the dependency on 'toml' was removed. Code that relied on automatic TOML loading may break.
fix
Install tomli and tomli-w (or use Python 3.11+'s tomllib) and adjust your config loading code to use them explicitly.
Warnings
breaking The 'toml' dependency was removed in v2.7.6. If you rely on automatic TOML config parsing, you must now use tomli/tomli-w or Python 3.11+'s tomllib. Code using cmdkit's Configuration with TOML will break unless you adapt. ↓
fix Upgrade to cmdkit>=2.7.6 and ensure your Python version is 3.9+ (tomllib available on 3.11+; for older Python, install tomli and tomli-w).
breaking Python 3.10+ requirement was relaxed in v2.7.7 to 3.9+. If you are on Python 3.9, upgrade to v2.7.7. If you pin to an older version, you may get installation failures on Python 3.9. ↓
fix Pin cmdkit>=2.7.7 to support Python 3.9.
deprecated The 'toml' package used by cmdkit is deprecated and no longer maintained. cmdkit v2.7.6+ removed this dependency. ↓
fix Upgrade to cmdkit>=2.7.6 to switch to tomli/tomli-w or use Python's standard library (tomllib).
gotcha When subclassing Command, ensure you call super().__init__(name=name) or you may encounter missing attributes like 'logger'. ↓
fix Always call super().__init__(name=name) in your Command subclass constructor.
Imports
- Command wrong
from cmdkit.cli import Commandcorrectfrom cmdkit import Command - Namespace
from cmdkit import Namespace
Quickstart
from cmdkit import Command, Namespace
class MyApp(Command):
name = 'myapp'
usage = 'myapp [options]'
description = 'A sample CLI application'
interface = Command.build_interface(
'MyApp',
'A sample CLI app',
'v1.0'
)
def __init__(self, name=None):
super().__init__(name=name)
# Add subcommands, options, etc.
if __name__ == '__main__':
MyApp.main()