Python Dependencies¶
🔍🛠️ Overview¶
Managing Python dependencies cleanly and reproducibly is essential for stable development and deployment workflows. Poetry is a modern tool to handle Python packaging and dependency management effectively.
💡 Key Features¶
- Simplifies dependency management and packaging
- Creates isolated virtual environments automatically (optional)
- Supports locking dependencies for reproducible installs
- Easy to use CLI for installing, updating, and publishing packages
🚀 Use Cases¶
- Managing dependencies in Python projects
- Creating reproducible environments for local development and CI/CD
- Packaging Python libraries for distribution
⚙️ Setup & Configuration¶
To use Poetry for dependency management in Docker, add the following lines in your Dockerfile:
COPY pyproject.toml ./
RUN pip3 install poetry
RUN poetry config virtualenvs.create false
RUN poetry install -n --no-ansi --without dev
Where:
-n disables interactive prompts
--no-ansi disables colored output
--without dev skips development dependencies
This ensures a clean production install with only necessary packages.
📚 Resources¶
🧠 Notes & Tips¶
- Use
poetry lock
to update the lock file when dependencies change. - Avoid installing dev dependencies in production to keep image size small.
- Combine Docker layers efficiently to speed up builds.
⚡ uv: A Promising Alternative for Fast Python Installations¶
uv is a fast Python package installer written in Rust. It offers significantly faster installation times compared to traditional pip or poetry installs, making it an excellent choice to speed up dependency management, especially in CI/CD pipelines and Docker builds.
Advantages of using uv:
- Blazing-fast package installation
- Lightweight and minimal dependencies
- Compatible with existing Python packaging workflows
- Ideal for improving build and deployment times