Shipping your CLI
Ways to run a Clak app from the command line — from a local script to an installed console entry point.
- Call with the Python interpreter:
python script.py … - Make the file executable on Unix-like systems
- Package as a
console_scripts/ Poetry / PDM / UV entry point
Clak does not replace packaging; it replaces hand-rolled argparse wiring inside
your main.
Without package managers
With the Python interpreter
-
Create your script (Clak example):
-
Run it:
As an executable script
- Keep the shebang (
#!/usr/bin/env python3). chmod +x script.py- Run
./script.py --help(or put the directory on$PATH).
With package managers
Expose a function that constructs your root Parser (instantiation runs
dispatch). Prefer returning/sys.exiting an int only if you call dispatch
yourself with parse=False patterns; for the default App() style, the
entry point can simply construct the app.
Setuptools
# setup.py
from setuptools import setup
setup(
name="your-package",
version="0.1.0",
packages=["your_package"],
entry_points={
"console_scripts": [
"your-command=your_package.cli:main",
],
},
)
Poetry
PDM / UV
Best practices
- Use a clear command name that does not collide with system tools.
- Rely on Clak/
argparsehelp instead of a custom usage printer. - Raise
ClakUserError(or your app errors) and let Clak set exit codes — see Error handling. - For tab completion after install, emit a script with Completion using the installed executable name.