Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Python
Stage 5: Specialization

Part 16 / Stage 3

Packaging and modern Python

Goal: Turn a script into a real, installable, publishable Python package: a proper command-line interface, a pyproject.toml, an editable install, the uv tool, a release to PyPI, and a tour of what actually changed in Python 3.10–3.14. Time: ~1 hour

Part 7 covered venv, pip install and requirements.txt — one project, one private folder of packages. This part is about the next step: turning your own code into something that installs with one command, runs as a short command (not python long/path/to/file.py), and can be shared with the world. If you have not read Part 7, read it first; this part does not repeat venv or pip basics.

What you will learn

  • Building a real command-line tool with argparse: subcommands, typed arguments, defaults, auto-generated --help
  • The modern project layout (src/) and every table in pyproject.toml
  • Editable installs (pip install -e .) and why they exist
  • uv: the fast all-in-one project manager (init, add, run, lock, build, publish)
  • Versioning a package and publishing it to PyPI, TestPyPI first
  • What is actually new in Python 3.10 through 3.14 — only the parts you can run and check for yourself

Topics in this part

Practice

Python workbench — write and run code here

Press Run and Python 3.14 loads right in your browser (a one-time download of about 15 MB; after that it works offline). Your code never leaves this page. input() opens a small prompt window.

Each topic above carries its own exercise and solution — open a topic and scroll to its exercise. All 6 exercises are also counted on the Python Practice page.

Common mistakes

Mistake Why it is wrong Fix
python my_cli.py --people 3 instead of real subcommands no structure as the tool grows; every flag means something different depending on context add_subparsers(), one sub-parser per action
Catching every argparse problem with a bare except: hides real bugs, and argparse already prints a clear error itself let SystemExit happen in real CLI use; only catch it in a demo/test
Package folder sitting next to its tests, no src/ tests can "pass" against a stray folder on disk, not the installed package use the src/ layout (section 2)
Editing __init__.py's version and pyproject.toml's version separately they drift out of sync keep one source of truth: pyproject.toml, read by __version__ if you need it in code, or a tool like uv version
pip install . while developing your own package every change needs a reinstall to take effect pip install -e .
Uploading straight to the real PyPI a typo or broken metadata is now live, and version numbers can never be reused upload to TestPyPI first, always
Uploading without twine check dist/* first metadata mistakes are only caught after a real upload check locally, for free, first
Writing "Python 3.14 added X" from memory easy to misremember which version added what check sys.version_info and actually run it, or read the official What's New page

Quick recap

  • argparse turns sys.argv into typed, checked data; add_subparsers() gives a tool several actions, each with its own arguments; bad input exits with code 2, automatically.
  • The src/ layout plus pyproject.toml ([project], [project.scripts], [build-system]) is the modern shape of an installable package; tomllib reads that same file from Python 3.11 on.
  • pip install -e . links to your source instead of copying it, so edits take effect without reinstalling — the standard way to develop your own package.
  • uv does venv + pip + locking + building + publishing with one tool and one pyproject.toml; uv init, uv add, uv run, uv lock, uv build, uv publish.
  • Bump the version, build a wheel + sdist, twine check them, publish to TestPyPI first, then to PyPI, with an API token.
  • Python 3.10–3.14 each added real, checkable features (match, tomllib, generic syntax, free-threading, t"..." strings); verify with the interpreter in front of you rather than trusting memory, and read the official docs for anything newer.

Checklist

  • I can write an argparse CLI with subcommands, typed arguments, choices= and a default, and explain the exit code for bad input.
  • I can lay out a package with src/, and explain every table in a pyproject.toml.
  • I can read a pyproject.toml with tomllib.
  • I can install my own package with pip install -e . and explain why it beats a plain install while developing.
  • I can start, add a dependency to, and run a project with uv, and know which classic command each uv command replaces.
  • I can build a wheel + sdist, check them with twine, and describe the TestPyPI-first publishing flow.
  • I can name at least one real, checkable feature from each of Python 3.10 through 3.14.

Search the guide