Learn: Packages and packaging¶
Six short tutorials that take you from import math to publishing your own package on PyPI. Each one is a Jupyter notebook — read it in the browser, and edit and run any code cell directly on the page.
The tutorials build on each other, so working through them in order is the fastest path. Each takes roughly fifteen to twenty minutes.
The sequence¶
- Modules and imports — what
importactually does;sys.modules,sys.path, and__name__. - Packages and namespaces — directories with
__init__.py, sub-packages, and absolute vs relative imports. - Installing third-party packages —
pip, PyPI, pinning versions, andrequirements.txt. - Virtual environments —
python -m venv, activation, and the per-project workflow. - Authoring a package — the
src/layout,pyproject.toml, and editable installs. - Building and publishing —
python -m build, TestPyPI, and PyPI.
A note on running the code¶
Tutorials 1, 2, and 5 use Python you can run directly on the page. Tutorials 3, 4, and 6 cover tools that live outside Python — pip, venv, python -m build, and friends — which need a real terminal. Where a code block is shell-only, it's flagged with a callout; copy the commands into your shell to follow along.
Before you start¶
You'll get more from these if you're already comfortable with Python functions, modules, and basic file I/O. If you've not yet worked through the Functions and File handling guides, those are good warm-ups.