Poetry: The Modern Python Package Manager


Poetry: The Modern Python Package Manager

python-poetry/poetry

2025-08-10

Hello there! As a fellow software engineer, I'm excited to talk about Poetry. It's a fantastic tool that makes managing Python projects a whole lot easier. Think of it as a modern, all-in-one solution for your project's dependencies and packaging. It's designed to be intuitive and streamline your development workflow.

Poetry addresses several common headaches we face as developers

Dependency Management
It solves the "it works on my machine" problem by creating a deterministic dependency graph. When you add a new dependency, it figures out all the necessary sub-dependencies and their versions, ensuring everyone on the team has the exact same environment. This is a massive improvement over pip and requirements.txt, which can lead to inconsistencies.

Virtual Environment Management
You no longer need to manually create and activate virtual environments. Poetry handles this automatically. When you start a new project, it creates a dedicated virtual environment for you, keeping your global Python installation clean. It's like having a separate, isolated workspace for each project.

Simplified Packaging and Publishing
Creating and publishing your Python package to the PyPI (Python Package Index) can be a pain. Poetry makes this process incredibly simple. It generates all the necessary files (like pyproject.toml) and commands to build and publish your package are straightforward.

Project Structure
It encourages a clean, standardized project structure. Your project's metadata, dependencies, and scripts are all defined in a single file, pyproject.toml, which is a modern standard. This eliminates the need for setup.py, requirements.txt, and other separate files.

Getting Poetry up and running is a breeze.

You can install it using a simple one-line command.

For macOS/Linux/WSL

curl -sSL https://install.python-poetry.org | python3 -

For Windows (PowerShell)

(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -

After installation, make sure the Poetry executable is in your system's PATH.

To create a brand new project, just run

poetry new my-awesome-project
cd my-awesome-project

This command creates a directory named my-awesome-project with a basic project structure, including a pyproject.toml file.

This is where the magic happens. To add a library like requests, simply use the add command

poetry add requests

Poetry will fetch the requests package and all its dependencies, install them in your virtual environment, and update your pyproject.toml and poetry.lock files.

To execute a Python script within your project's virtual environment, you can use the run command

poetry run python my_script.py

This ensures your script uses the dependencies you've installed with Poetry.

When your package is ready to be shared, publishing it to PyPI is a piece of cake.

First, you'll need to configure your PyPI credentials
poetry config pypi-token.pypi <your_token>

Then, simply run
poetry publish --build

This command will build your package and upload it to PyPI.

Here's what your pyproject.toml file might look like for a simple project that uses requests and rich to make an API call and print a pretty output.

pyproject.toml

[tool.poetry]
name = "my-awesome-project"
version = "0.1.0"
description = "A simple API client."
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
requests = "^2.31.0"
rich = "^13.7.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

The [tool.poetry.dependencies] section is where you list all your direct dependencies. The caret ^ means Poetry can use any version of the package that is backward compatible.

Here's an example of a simple Python script you might write.

main.py

import requests
from rich.console import Console

def get_data(url: str):
    """Fetches data from a given URL."""
    try:
        response = requests.get(url)
        response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)
        return response.json()
    except requests.exceptions.RequestException as e:
        print(f"Error fetching data: {e}")
        return None

if __name__ == "__main__":
    console = Console()
    api_url = "https://api.github.com/users/google"
    user_data = get_data(api_url)

    if user_data:
        console.print("[bold green]User Data:[/bold green]")
        console.print(f"Name: [cyan]{user_data.get('name')}[/cyan]")
        console.print(f"Location: [cyan]{user_data.get('location')}[/cyan]")
        console.print(f"Followers: [cyan]{user_data.get('followers')}[/cyan]")
        console.print(f"Public Repos: [cyan]{user_data.get('public_repos')}[/cyan]")

To run this, you would simply execute poetry run python main.py from your project's root directory.


python-poetry/poetry




Shubhamsaboo/awesome-llm-apps

The Shubhamsaboo/awesome-llm-apps repository is a fantastic resource for software engineers looking to dive into the world of Large Language Model (LLM) applications


Automating Your Playlist: A Software Engineer's Take on spotDL

As a software engineer, you might find spotDL useful in several waysOffline Music for Development Environments We all know how important it is to have a good playlist to focus while coding


Mastering Machine Learning: A Software Engineer's Guide to Microsoft's ML-For-Beginners

Let's dive into microsoft/ML-For-Beginners from a software engineer's perspective. This is a fantastic resource, and I'll explain how it can benefit you


Accelerating Kernels: Why cuTile-python is a Game Changer for Software Engineers

Think of it as a bridge that brings the efficiency of Tiling (a core GPU optimization technique) into the flexibility of Python


tags, suitable for articles or documentation:

Here is an explanation of how it can be useful, along with deployment and sample code considerations, from a software engineer's perspective


LEANN: The Software Engineer's Secret Weapon for Private and Portable RAG

LEANN is an innovative, open-source vector database designed for the modern, privacy-focused RAG stack. Its key value propositions are


The Engineer's Toolkit for Digital Libraries: Getting Started with Calibre

While many people know it as "that desktop app for ebooks, " for us developers, it’s actually a powerful, Python-based toolkit for document manipulation and library management


From Minutes to Hours: Mastering Multi-Agent Orchestration with Deer-Flow

Let’s dive into Deer-Flow by ByteDance. Think of it not just as another chatbot, but as a highly capable digital coworker that can handle the "heavy lifting" of research and coding


Building and Scaling LLM Applications with TensorZero

TensorZero is an all-in-one toolkit designed to help you build, deploy, and manage industrial-grade LLM applications. Think of it as a comprehensive platform that covers the entire lifecycle of an LLM app


Modern Web Scraping in Python: How Scrapling Uses Adaptive Logic to Handle the Messy Web

Think of it as a more flexible, modern alternative to Scrapy or BeautifulSoup. It's designed to be adaptive, meaning it doesn't just break the moment a dev changes a class name on a website