Introduction to PDM
PDM is a modern Python package and dependency manager that aligns with the latest Python Enhancement Proposals (PEPs). It was initially developed for personal use but has grown to provide a robust alternative for those seeking features not available in existing tools like Pipenv or Poetry.
Features of PDM
- Fast Dependency Resolution: It excels in quickly resolving dependencies, particularly for large binary distributions.
- PEP 517 Build Backend: PDM supports building packages using the PEP 517 standard.
- PEP 621 Project Metadata: It uses the PEP 621 standard for project metadata, ensuring that your project configuration stays consistent and modern.
- Flexible Plugin System: Users can extend PDM’s functionality through an adaptable and powerful system of plugins.
- User Scripts: It offers versatile scripting options for users to automate their workflows.
- Python Installation: PDM can install Python versions as needed, utilizing indygreg's python-build-standalone.
- Centralized Cache: An optional centralized cache akin to
pnpm
is available to save disk space and boost installation speeds.
Comparing PDM with Other Tools
Pipenv is primarily aimed at handling non-installable applications but lacks features for packaging code. Poetry goes further, allowing building and uploading of packages, but it uses a non-standard approach for project metadata. Hatch offers multiple environments per project but lacks lockfile support and also deviates from metadata standards.
PDM effectively blends the best of these tools, offering virtual environment management at both the project and centralized levels, using a standardized pyproject.toml
file. It also provides flexibility in build backends and plugin options.
Installation
PDM requires Python version 3.8 or higher.
Via Installation Script
To install PDM on Linux or Mac, run:
curl -sSL https://pdm-project.org/install-pdm.py | python3 -
For Windows:
powershell -ExecutionPolicy ByPass -c "irm https://pdm-project.org/install-pdm.py | py -"
Alternative Methods
-
On macOS with Homebrew:
brew install pdm
-
On Windows with Scoop:
scoop install pdm
-
Using
pipx
, an isolated environment:pipx install pdm
-
Or, install under a user site with
pip
:pip install --user pdm
-
With
asdf-vm
:asdf plugin add pdm asdf install pdm latest
Quickstart with PDM
Initialize a New Project
Start a new project by running:
pdm init
Follow the prompts to set up your project.
Add Dependencies
To install dependencies like requests
and flask
, use:
pdm add requests flask
Review the pdm.lock
file to see the locked versions of the packages.
Community and Contribution
PDM is part of an ecosystem that includes plugins and resources managed under Awesome PDM. Developers are encouraged to contribute and share plugins by uploading them as distributions.
Acknowledgments and License
Inspired by tools like pyflow and poetry, PDM is released under the MIT license, and its source code and license details can be found in the LICENSE file of the project.