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




Microsoft Qlib Explained: An Engineer's Guide to AI in Finance

Hey there! As a software engineer, you're always on the lookout for tools that can streamline complex processes and open up new possibilities


Technical Breakdown: How TrendRadar's NLP Features Streamline Software Engineering Tasks

Here is a friendly, detailed breakdown, focusing on the technical value and implementation steps.The sansan0/TrendRadar project is essentially a sophisticated AI-driven news aggregation and monitoring system


From Code to Components: Integrating with InvenTree as a Developer

Let's dive into InvenTree from a software engineer's perspective. It's a fantastic open-source inventory management system


Why Ultralytics YOLO is the Go-To Toolkit for Production-Ready AI Tracking

Here is a breakdown of why it’s a game-changer for engineers and how you can get started.In the past, computer vision (CV) required deep knowledge of academic math and complex C++ libraries


The Engineering Value of '30-Days-Of-Python' and How to Start

Here's a friendly breakdown of how it's useful, how to get started, and a quick example of the kind of code you'll encounter


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


Django for Perfectionists: A "Batteries-Included" Approach to Web Frameworks

Django is a powerful, high-level Python web framework that encourages rapid development and clean, pragmatic design. From a software engineer's perspective


Scaling AI Accuracy: An Engineering Walkthrough of Modern RAG Architectures

If you've been working with Large Language Models (LLMs), you probably know that "out-of-the-box" models often hallucinate or lack specific


Social-Analyzer: A Software Engineer's Guide to OSINT Integration

This is a powerful OSINT (Open-Source Intelligence) tool designed to automatically find and analyze a person's profile across a vast network of over 1000 social media platforms and websites using a given username


A Developer's Walkthrough of the FastAPI Full-Stack Template

At its core, the full-stack-fastapi-template is a pre-configured project that bundles a bunch of modern technologies together