PEP 621 Metadata#
The project metadata are stored in the pyproject.toml
. The specifications are defined by PEP 621, PEP 631 and PEP 639. Read the detailed specifications in the PEPs.
In the following part of this document, metadata should be written under [project]
table if not given explicitly.
Multiline description#
You can split a long description onto multiple lines, thanks to TOML support for multiline strings. Just remember to escape new lines, so the final description appears on one line only in your package metadata. Indentation will be removed as well when escaping new lines:
1 2 3 4 5 6 |
|
See TOML's specification on strings.
Package version#
1 2 |
|
1 2 3 4 5 6 |
|
The version will be read from the mypackage/__version__.py
file searching for the pattern: __version__ = "{version}"
.
Read more information about other configurations in dynamic project version from the pdm-backend
documentation.
Python version#
The required version of Python is specified as the string requires-python
:
1 2 3 4 5 6 7 8 |
|
Note: As per PEP 621,
PDM is not permitted to dynamically update the classifiers
section like some other non-compliant tools.
Thus, you should also include the appropriate trove classifiers as shown above if you plan on publishing your package on PyPI.
License#
The license is specified as the string license
:
1 2 3 4 5 |
|
Note: As per PEP 621,
PDM is not permitted to dynamically update the classifiers
section like some other non-compliant tools.
Thus, you should also include the appropriate trove classifiers as shown above if you plan on publishing your package on PyPI.
Dependency specification#
The project.dependencies
is an array of dependency specification strings following the PEP 440 and PEP 508.
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Optional dependencies#
You can have some requirements optional, which is similar to setuptools
' extras_require
parameter.
1 2 3 4 5 6 7 |
|
To install a group of optional dependencies:
1 |
|
-G
option can be given multiple times to include more than one group.
Context variables expansion#
Depending on which build backend you are using, PDM will expand some variables in the dependency strings.
Environment variables#
1 2 |
|
1 2 |
|
Find more usages here
Don't worry about credential leakage, the environment variables will be expanded when needed and kept untouched in the lock file.
Relative paths#
When you add a package from a relative path, PDM will automatically save it as a relative path for pdm-backend
and hatchling
.
For example, if you run pdm add ./my-package
, it will result in the following line in pyproject.toml
.
1 2 |
|
1 2 |
|
By default, hatchling doesn't support direct references
in the dependency string, you need to turn it on in pyproject.toml
:
1 2 |
|
The relative path will be expanded based on the project root when installing or locking.
Console scripts#
The following content:
1 2 |
|
will be translated to setuptools
style:
1 2 3 4 5 |
|
Also, [project.gui-scripts]
will be translated to gui_scripts
entry points group in setuptools
style.
Entry points#
Other types of entry points are given by [project.entry-points.<type>]
section, with the same format of [project.scripts]
:
1 2 |
|
If the entry point name contains dots or other special characters, wrap it in quotes:
1 2 |
|