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.

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

  1. Write package code and tests.
  2. Define metadata in pyproject.toml.
  3. Build wheel and source distribution.
  4. Publish to PyPI or internal registry.
  5. 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

  1. Create a virtual environment and install a third-party package with pip.
  2. Generate a requirements.txt file and reinstall from it.
  3. Build a tiny package with pyproject.toml and produce wheel + sdist artifacts.
  4. Explain when your team should use public indexes versus private registries.