Back to results for “Commands”
Python › Modules & Packaging

How do entry points in packaging metadata enable a package to register CLI commands or plugins?

Advanced

Answer

Entry points, declared in pyproject.toml's [project.scripts] (for console commands) or [project.entry-points] (for arbitrary plugin groups), let a package advertise callables that other tools or the shell can discover and invoke by name after installation -- powering both `pip install`-generated CLI commands and plugin systems (like pytest plugins) that scan installed packages for registered entry points.
# pyproject.toml
[project.scripts]
mycli = "mypackage.cli:main"

# After pip install, running `mycli` in the shell calls mypackage.cli.main()
Real-world example A CLI tool distributed via PyPI declares a `[project.scripts]` entry point so that after `pip install mycli-tool`, users can simply type `mycli` in their terminal instead of `python -m mycli_tool`.

Common follow-ups: How does pytest discover plugins via entry points?;How do you inspect installed entry points programmatically with importlib.metadata?