Build a CLI with argparse and package it for pip

10 steps · about 4 h 35 min · Intermediate

  1. Argparse Tutorial (doc, Python docs, 30 min)

    The official gentle introduction. It covers positional arguments, optional flags and type conversion, which every CLI needs.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.