PDM Build Backend
pdm-backend is the PEP 517 compliant build backend utilized by PDM, a modern Python package manager. It supports the latest packaging standards for building source distributions (sdist) and wheels, including dynamic versioning from SCM, flexible metadata definition in pyproject.toml, and handling of various project layouts. The current version is 2.4.8, with a regular release cadence to incorporate new features and bug fixes.
Warnings
- gotcha SCM-based versioning requires a clean Git working tree and correct Git configuration. Errors can occur if Git is not found, if the repository is in a detached HEAD state without proper tags, or if `core.abbrev` is configured to a non-standard value.
- gotcha pdm-backend strictly adheres to PEP 621 for static metadata in `pyproject.toml`. Dynamic fields must be explicitly declared in `project.dynamic` and their values provided by build hooks or specific tool configurations.
- breaking Prior to 2.0, `pdm-backend` might have behaved differently with older PDM versions or `pyproject.toml` schemas. Users transitioning from older PDM setups might encounter packaging issues.
- gotcha While `pdm-backend` can be used with `python -m build`, its full power and seamless integration are achieved when used within the `pdm` CLI (e.g., `pdm build`). Using `pdm` ensures the correct environment and `pyproject.toml` interpretation.
Install
-
pip install pdm-backend -
pip install pdm
Imports
- build-backend specification
In pyproject.toml: build-backend = "pdm.backend"
Quickstart
# my_project/pyproject.toml
[project]
name = "my-package"
version = "0.1.0"
dynamic = ["dependencies", "optional-dependencies"]
description = "A minimal example package"
requires-python = ">=3.9"
license = { text = "MIT" }
authors = [
{ name = "Your Name", email = "your@example.com" }
]
[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"
# my_project/src/my_package/__init__.py
__version__ = "0.1.0"
# To build the package (run from my_project directory):
# 1. Ensure PDM is installed: pip install pdm
# 2. Run the build command:
# pdm build
# Or using the standard 'build' tool:
# pip install build
# python -m build