Skip to content

API Reference#

pdm.core.Core #

A high level object that manages all classes and configurations

add_config(name, config_item) staticmethod #

Add a config item to the configuration class.

Parameters:

Name Type Description Default
name str

The name of the config item

required
config_item pdm.project.config.ConfigItem

The config item to add

required

create_project(root_path=None, is_global=False, global_config=None) #

Create a new project object

Parameters:

Name Type Description Default
root_path PathLike

The path to the project root directory

None
is_global bool

Whether the project is a global project

False
global_config str

The path to the global config file

None

Returns:

Type Description
Project

The project object

load_plugins() #

Import and load plugins under pdm.plugin namespace A plugin is a callable that accepts the core object as the only argument.

Example
1
2
def my_plugin(core: pdm.core.Core) -> None:
    ...

main(args=None, prog_name=None, obj=None, **extra) #

The main entry function

register_command(command, name=None) #

Register a subcommand to the subparsers, with an optional name of the subcommand.

Parameters:

Name Type Description Default
command Type[pdm.cli.commands.base.BaseCommand]

The command class to register

required
name str

The name of the subcommand, if not given, command.name is used

None

Signals#

New in version 1.12.0

The signal definition for PDM.

Example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from pdm.signals import post_init, post_install

def on_post_init(project):
    project.core.ui.echo("Project initialized")
# Connect to the signal
post_init.connect(on_post_init)
# Or use as a decorator
@post_install.connect
def on_post_install(project, candidates, dry_run):
    project.core.ui.echo("Project install succeeded")

post_build: NamedSignal = pdm_signals.signal('post_build') module-attribute #

Called after a project is built.

Parameters:

Name Type Description Default
project Project

The project object

required
artifacts Sequence[str]

The locations of built artifacts

required
config_settings dict[str, str] | None

Additional config settings passed via args

required

post_init: NamedSignal = pdm_signals.signal('post_init') module-attribute #

Called after a project is initialized.

Parameters:

Name Type Description Default
project Project

The project object

required

post_install: NamedSignal = pdm_signals.signal('post_install') module-attribute #

Called after a project is installed.

Parameters:

Name Type Description Default
project Project

The project object

required
candidates dict[str, Candidate]

The candidates installed

required
dry_run bool

If true, won't perform any actions

required

post_lock: NamedSignal = pdm_signals.signal('post_lock') module-attribute #

Called after a project is locked.

Parameters:

Name Type Description Default
project Project

The project object

required
resolution dict[str, Candidate]

The resolved candidates

required
dry_run bool

If true, won't perform any actions

required

post_publish: NamedSignal = pdm_signals.signal('post_publish') module-attribute #

Called after a project is published.

Parameters:

Name Type Description Default
project Project

The project object

required

post_run: NamedSignal = pdm_signals.signal('post_run') module-attribute #

Called after any run.

Parameters:

Name Type Description Default
project Project

The project object

required
script str

the script name

required
args Sequence[str]

the command line provided arguments

required

post_script: NamedSignal = pdm_signals.signal('post_script') module-attribute #

Called after any script.

Parameters:

Name Type Description Default
project Project

The project object

required
script str

the script name

required
args Sequence[str]

the command line provided arguments

required

post_use: NamedSignal = pdm_signals.signal('post_use') module-attribute #

Called after use switched to a new Python version.

Parameters:

Name Type Description Default
project Project

The project object

required
python PythonInfo

Informations about the new Python interpreter

required

pre_build: NamedSignal = pdm_signals.signal('pre_build') module-attribute #

Called before a project is built.

Parameters:

Name Type Description Default
project Project

The project object

required
dest str

The destination location

required
config_settings dict[str, str] | None

Additional config settings passed via args

required

pre_install: NamedSignal = pdm_signals.signal('pre_install') module-attribute #

Called before a project is installed.

Parameters:

Name Type Description Default
project Project

The project object

required
candidates dict[str, Candidate]

The candidates to install

required
dry_run bool

If true, won't perform any actions

required

pre_lock: NamedSignal = pdm_signals.signal('pre_lock') module-attribute #

Called before a project is locked.

Parameters:

Name Type Description Default
project Project

The project object

required
requirements list[Requirement]

The requirements to lock

required
dry_run bool

If true, won't perform any actions

required

pre_publish: NamedSignal = pdm_signals.signal('pre_publish') module-attribute #

Called before a project is published.

Parameters:

Name Type Description Default
project Project

The project object

required

pre_run: NamedSignal = pdm_signals.signal('pre_run') module-attribute #

Called before any run.

Parameters:

Name Type Description Default
project Project

The project object

required
script str

the script name

required
args Sequence[str]

the command line provided arguments

required

pre_script: NamedSignal = pdm_signals.signal('pre_script') module-attribute #

Called before any script.

Parameters:

Name Type Description Default
project Project

The project object

required
script str

the script name

required
args Sequence[str]

the command line provided arguments

required