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
| Topic | Key Points |
|---|---|
| pyproject.toml | Single config file for metadata and tools |
| src/ layout | Recommended for libraries |
| Dependencies | Specify ranges, lock for apps |
| Virtual envs | Isolate project dependencies |
| Building | Use python -m build |
| Publishing | Test on TestPyPI first |
| CLI apps | Use 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!