Packaging and Distribution: Ship Your Python

Learning Objectives: After this lesson, you'll understand modern Python packaging with pyproject.toml, manage dependencies effectively, create and publish packages to PyPI, and structure professional Python projects.

Modern Python Packaging

Python packaging has evolved significantly. Let's understand the modern approach.

Loading tool...

The Packaging Landscape

Loading tool...

pyproject.toml

Loading tool...

Project Structure

Loading tool...
Loading tool...

Package Initialization

Loading tool...

Dependency Management

Understanding Dependencies

Loading tool...

Lock Files

Loading tool...

Virtual Environments

Loading tool...

Building and Publishing

Loading tool...

Building Your Package

Loading tool...

Publishing to PyPI

Loading tool...

CLI Applications

Loading tool...

Configuration Management

Loading tool...

Best Practices

Loading tool...

Practice Exercise

Complete Package Setup

Loading tool...

Key Takeaways

TopicKey Points
pyproject.tomlSingle config file for metadata and tools
src/ layoutRecommended for libraries
DependenciesSpecify ranges, lock for apps
Virtual envsIsolate project dependencies
BuildingUse python -m build
PublishingTest on TestPyPI first
CLI appsUse Click + entry points

Essential Commands

# Virtual environment python -m venv .venv source .venv/bin/activate # Install in development mode pip install -e ".[dev]" # Build package python -m build # Upload to PyPI twine upload dist/* # Check package pip install --index-url https://test.pypi.org/simple/ mypackage

Next Steps

In the next and final lesson, we'll bring everything together in a Capstone Project: Building a Production-Ready CLI Tool—applying all concepts from the course in a comprehensive project.


Ready for the final project? Let's build something real!