Course contentsShow
← Data Science
Lesson 2051 of 2,14547. Reproducible ResearchFree lesson

Poetry and Modern Python Tools

Using Poetry or Pipenv for dependency resolution, lock files, and separating development from production dependencies.

Poetry and Modern Python Tools

You'll learn how Poetry and Pipenv solve dependency chaos with lock files, deterministic installs, and clean separation of dev vs. production packages.

The Problem Poetry Solves

Remember requirements.txt and version pinning from earlier lessons? Those approaches have limitations: they don't automatically resolve sub-dependencies, can produce different environments on different machines, and mixing development tools with production code gets messy.

Poetry (and similarly, Pipenv) are modern dependency managers that treat your project like a publishable package from day one. Think of them as "package managers with a brain"—they automatically resolve the entire dependency tree, ensure everyone gets identical versions, and keep your testing tools separate from production code.

How Poetry Works

Poetry uses two key files:

  • pyproject.toml: declares what you want (package names, version ranges)
  • poetry.lock: records what you got (exact versions of everything, including sub-dependencies)

When you run poetry install, it reads the lock file and installs precisely those versions—no surprises across machines or time.

Development vs Production Dependencies

Poetry shines at separating concerns:

[tool.poetry.dependencies]
python = "^3.9"
pandas = "^2.0"
scikit-learn = "^1.3"

[tool.poetry.group.dev.dependencies]
pytest = "^7.0"
jupyter = "^1.0"
black = "^23.0"

Development dependencies (testing, formatting, notebooks) install locally but won't ship with your production model. This keeps deployment lean and secure.

The Analogy

Poetry is like a smart recipe manager: you specify ingredients (dependencies), it finds compatible brands and batches (versions), writes down the exact products used (lock file), so anyone can recreate your dish identically—and keeps cooking tools separate from the meal itself.

Key Takeaway: Poetry and Pipenv automate dependency resolution, create reproducible lock files, and cleanly separate development from production dependencies—solving "works on my machine" problems in collaborative data science.