Python packages and environments

Using uv for the course Python environment

This course uses uv to manage Python 3.12, the virtual environment, project dependencies, and the lockfile. The labs repository already contains the project configuration; you usually need only the commands on this page.

Set up the lab environment

From the root of your cloned is4010-labs repository:

uv sync --locked

This command reads:

  • .python-version for the course Python version
  • pyproject.toml for direct dependencies
  • uv.lock for the exact resolved environment

It creates .venv automatically. You do not need to activate it because uv run selects the project environment for each command.

The lock file also includes the dev dependency group, which uv installs by default. That is why pytest is available even though requests is the only direct dependency listed in pyproject.toml.

Run Python and tests

# Check the managed Python version
uv run python --version

# Run a script
uv run python path/to/script.py

# Run the test command printed in a lab
uv run --directory week03 python -m pytest tests/ -v

Use python -m pytest after uv run; this makes the project interpreter and import path explicit.

Add a dependency to your own project

The course repository’s dependencies are instructor-managed. In your own project, use:

uv add requests
uv add --dev pytest

uv add updates both pyproject.toml and uv.lock. Commit those two files so collaborators and CI reproduce the same environment.

Keep the environment synchronized

# Reproduce the committed lockfile exactly
uv sync --locked

# Intentionally update the lockfile after changing dependencies
uv lock

Do not commit .venv; it is a machine-local build artifact. Do commit .python-version, pyproject.toml, and uv.lock.

For additional workflows, use the official uv project guide and uv run documentation.