PDM: Python Dependency Management

PDM for dependency management and resolution

PDM is the latest package offering dependency resolution and management in the Python ecosystem. How does it compare to other more established tools such as Poetry and Pip?
 

The Next Generation Python Package Management Tool

Python developers are always on the lookout for the best package management tools to enhance their workflow. PDM (Python Development Master) is a next-generation Python package management tool that aims to streamline your development process. It was originally built for personal use, but if you’re struggling with existing tools like Pipenv or Poetry, PDM might just have the features you need.

PDM is not just a package manager; it also enhances your development workflow in various ways. The most significant benefit is its ability to manage packages in a similar manner to npm, without the need to create a virtualenv at all!
 

Project Structure

PDM follows the PEP 582 project structure, which simplifies the management of dependent libraries. A typical project structure looks like this:

foo
    __pypackages__
        3.8
            lib
                bottle
    myscript.py


 

Features Highlights:

Some of the standout features of PDM include:

PEP 582 local package installer and runner with no virtualenv involved. Simple and fast dependency resolver, perfect for large binary distributions. PEP 517 build backend. Flexible and powerful plug-in system. PEP 621 project metadata format. Opt-in centralized installation cache, similar to pnpm. Why Not Virtualenv? Traditional Python packaging tools often act as virtualenv managers to isolate project environments. However, things can get tricky with nested virtual environments. PEP 582 provides a way to decouple the Python interpreter from project environments, making it a more attractive option.
 

Installation:

To install PDM, you’ll need Python version 3.7 or higher. PDM offers an installation script for Linux/Mac and Windows that installs it into an isolated environment. You can also use alternative installation methods, such as Homebrew for MacOS, Scoop for Windows, pipx, or pip under a user site.

Quickstart:

To get started with PDM, follow these steps:

  1. Initialize a new PDM project with pdm init. This creates a pyproject.toml file.
  2. Install dependencies into the pypackages directory with pdm add <dependencies>.
  3. Run your script with PEP 582 support by setting the environment variable with eval "$(pdm --pep582)".

PDM is a powerful package management tool that simplifies the development process and provides various benefits over traditional Python package management methods. Give it a try and see if it’s the right fit for your projects!