Python Ecosystem
This lesson explains how Python packages are organized, indexed, downloaded, and distributed across the internet, from local installs to public registries.
Package Managers
Python package managers resolve dependencies, install packages, lock versions, and help teams reproduce environments. The most common tools are pip, Poetry, and Conda.
- pip: the default installer for Python packages from package indexes.
- Poetry: dependency management plus packaging workflow with lock files.
- Conda: environment and binary distribution manager used heavily in scientific computing.
python -m venv .venv
. .venv/Scripts/activate
python -m pip install --upgrade pip
pip install requests
pip freeze > requirements.txt
Internet Organization
Python packages are typically organized through package indexes. The public default is PyPI, but teams can also use private indexes, internal artifact registries, or mirrored caches.
- Public index: PyPI
- Install client: pip
- Packaging guide: Packaging User Guide
When you run an install command, the client resolves metadata, downloads package artifacts, checks dependency constraints, and installs files into your environment.
Distribution Formats
Python packages are usually distributed in two main formats:
- sdist: source distribution, built from source on install.
- wheel: prebuilt binary or pure-Python distribution, faster and more predictable to install.
python -m build
# produces:
# dist/project_name-0.1.0.tar.gz
# dist/project_name-0.1.0-py3-none-any.whl
Package Structure
A minimal distributable project usually contains package code, metadata, dependency declarations, tests, and documentation.
my_project/
pyproject.toml
README.md
src/
my_project/
__init__.py
service.py
tests/
test_service.py
Publishing Flow
- Write package code and tests.
- Define metadata in
pyproject.toml. - Build wheel and source distribution.
- Publish to PyPI or internal registry.
- Install from a clean environment and verify runtime behavior.
pip install build twine
python -m build
python -m twine check dist/*
python -m twine upload dist/*
Ecosystem Lab
- Create a virtual environment and install a third-party package with pip.
- Generate a
requirements.txtfile and reinstall from it. - Build a tiny package with
pyproject.tomland produce wheel + sdist artifacts. - Explain when your team should use public indexes versus private registries.