Build a CLI with argparse and package it for pip
10 steps · about 4 h 35 min · Intermediate
- Argparse Tutorial (doc, Python docs, 30 min)
The official gentle introduction. It covers positional arguments, optional flags and type conversion, which every CLI needs.
- argparse — Parser for command-line options, arguments and subcommands (reference, Python docs, 30 min)
Once you know the basics, the reference shows add_argument options and subcommands for tools with several actions.
- The Packaging Flow (doc, Python Packaging User Guide, 10 min)
A short map of the whole journey, from source tree to config file to build artifacts to PyPI, before you touch any tooling.
- Make your Python package PyPI ready - pyproject.toml (tutorial, pyOpenSci Python Packaging Guide, 25 min)
Explains the metadata tables in pyproject.toml that make a package installable and publishable.
- Python Packaging: Building and Installing Packages using setuptools (tutorial, The Carpentries Incubator, 30 min)
Walks through a minimal pyproject.toml and a local pip install, so you can test your tool on your own machine.
- How to Create and Distribute a Python CLI Tool (guide, pydevtools handbook, 15 min)
Shows how a console_scripts entry point turns your main() function into a command on the user's PATH.
- Packaging Python Projects (tutorial, Python Packaging User Guide, 45 min)
The official end-to-end tutorial covers the src layout, build backends, building distributions and uploading them.
- How to Manage Python Projects With pyproject.toml (article, Real Python, 30 min)
Goes deeper on dependencies, dynamic metadata and local installs once your first package works.
- How to Publish an Open-Source Python Package to PyPI (tutorial, Real Python, 40 min)
Covers project.scripts and the Twine upload flow, with a TestPyPI rehearsal before the real release.
- How to Publish to TestPyPI with uv (guide, pydevtools handbook, 20 min)
The last step is a modern uv workflow. Rehearse on TestPyPI, check the install, then promote the release to PyPI.