A package is a library of pre-written Python code you can drop into your project. Almost everything you’ll ever want — talking to web APIs, parsing CSV files, training neural networks, drawing charts — already exists as a package on the Python Package Index (PyPI).

In this lesson, we’ll install one and use it.

Add a package

We’ll install rich — a library for printing beautifully formatted output in the terminal. It’s useful, friendly, and a good test case.

From inside your project folder:

uv add rich
Resolved 4 packages in 12ms
   Installed 4 packages in 18ms
    + markdown-it-py==3.0.0
    + mdurl==0.1.2
    + pygments==2.18.0
    + rich==13.9.0

Two things happened:

  1. rich was downloaded from PyPI and installed into your project’s .venv/.
  2. pyproject.toml was updated with rich as a dependency.

Open pyproject.toml:

[project]
name = "python-fundamentals"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
    "rich>=13.9.0",
]

A new file also appeared: uv.lock. That file pins the exact version of every package (including dependencies of dependencies). You should commit uv.lock to git — it’s what guarantees other developers get the same versions you have.

Use the package

Open main.py and replace its contents:

from rich import print
from rich.table import Table


def main() -> None:
    print("[bold green]Hello, Python![/bold green]")

    table = Table(title="Course Sections")
    table.add_column("No.", style="cyan")
    table.add_column("Title", style="magenta")
    table.add_row("1", "Getting Started")
    table.add_row("2", "Variables and Types")
    table.add_row("3", "Operators and Expressions")

    print(table)


if __name__ == "__main__":
    main()

Run it:

uv run python main.py

You’ll see a green “Hello, Python!” followed by a coloured table. Rich did all the work.

We’ll cover import, from, and function syntax properly in later sections. For now, the point is: you can install a library and start using it in a few lines.

Remove a package

If you decide you don’t need rich:

uv remove rich

It’s removed from both .venv/ and pyproject.toml. (We won’t actually remove it for now — we might use it again later.)

Install everything from pyproject.toml

If you clone someone else’s project (or your own from another machine), the .venv/ won’t be there. Run:

uv sync

uv reads pyproject.toml and uv.lock, creates the venv, and installs every package at exactly the locked versions. One command, ready to run.

A note on pip

You may have seen older tutorials say:

pip install rich

Inside a uv project, you can do the equivalent with uv pip install rich — but it won’t update pyproject.toml. The right way is always uv add. Stick with it.

pip is still useful for global tools and quick one-offs outside a project. We’ll prefer uv add and uv tool install throughout this course.

Where to find packages

PyPI has hundreds of thousands of packages. A few you’ll meet later in this course or in your AI work:

  • numpy — numerical arrays (Section 16)
  • pandas — data tables
  • requests — make HTTP calls
  • pydantic — validate and parse data with types
  • scikit-learn — classical machine learning
  • torch — deep learning with PyTorch

You can browse PyPI at pypi.org — but most of the time you’ll find packages through tutorials, blog posts, or the official docs of whatever you’re trying to do.

What’s next

You’ve got a working Python environment, an editor that catches mistakes, automatic formatting and linting, a virtual environment, and the ability to install any library on PyPI.

That’s the foundation. From here on, every section is about Python itself — the actual language. We’ll start with variables and primitive types.

Toggle theme (T)