API reference

Loader

The driver consumed by build backends.

dynamic_metadata.loader.dynamic_wheel_fields(entries)

Collect the fields to mark Dynamic in SDist metadata (METADATA 2.2).

Asks each provider’s optional dynamic_wheel hook which fields may legitimately differ between the SDist and a wheel built from it. A field is dynamic if any provider reports it True: contributions to a field merge, so one dynamic part makes the merged value dynamic (PEP 643 permits marking a field Dynamic even when its value is also given). A field no provider mentions is not dynamic, and version may never be.

Providers are loaded fresh here, so dynamic_wheel cannot rely on state from a dynamic_metadata call.

Parameters:

entries (Sequence[Mapping[str, Any]])

Return type:

set[str]

dynamic_metadata.loader.get_requires_for_dynamic_metadata(entries)

Collect every provider’s extra build requirements, in entry order.

Call this from each PEP 517 get_requires_for_build_* hook. A provider without the optional get_requires_for_dynamic_metadata hook contributes nothing.

Parameters:

entries (Sequence[Mapping[str, Any]])

Return type:

list[str]

dynamic_metadata.loader.load_dynamic_metadata(entries)

Load each entry’s provider, yielding it with its plugin settings.

Entries are processed in order; provider is consumed here and the remaining keys are returned as plugin settings.

Parameters:

entries (Sequence[Mapping[str, Any]])

Return type:

Generator[tuple[DynamicMetadataProtocol, dict[str, Any]], None, None]

dynamic_metadata.loader.load_provider(provider)

Load a provider from its config value, returning the object whose hooks are called.

provider is the value of the provider key in a [[tool.dynamic-metadata]] entry, in one of two forms:

  • a string — a name registered in the PROVIDER_GROUP entry-point group. Installed plugins are only reachable this way; a raw import path is not accepted.

  • an inline table {path, module} — a local plugin imported from the path directory as a module path ("pkg.mod" or "pkg.mod:Class"), for a plugin living inside the project being built. Entry points are not consulted.

A bare module is returned as-is (hooks are module-level functions); a class is instantiated with no arguments so its hooks are bound methods sharing state through self; an already-instantiated object is used directly.

Parameters:

provider (object)

Return type:

DynamicMetadataProtocol

dynamic_metadata.loader.process_dynamic_metadata(project, entries, build_state)

Process dynamic metadata.

Takes the original [project] table and an ordered list of [[tool.dynamic-metadata]] entries, and returns a new project table. Entries run in list order: each provider is called with a read-only snapshot of the project as resolved so far, so a later entry can read a field an earlier one produced via project[...]. A provider returns a dict fragment of the project table ({field: value, ...}) which is merged in.

build_state is the backend’s description of the current build. It must be one of these build states (BUILD_STATES): "sdist", "wheel", "editable", "metadata_wheel", or "metadata_editable". A provider that cares about it implements an optional build_state hook, called with this value before dynamic_metadata; providers that ignore it simply omit the hook.

Parameters:
Return type:

dict[str, Any]

Plugin protocols

The protocols a provider may implement. Every provider satisfies DynamicMetadataProtocol; the others add optional hooks.

class dynamic_metadata.protocols.DynamicMetadataProtocol(*args, **kwargs)
class dynamic_metadata.protocols.DynamicMetadataBuildStateProtocol(*args, **kwargs)
class dynamic_metadata.protocols.DynamicMetadataRequirementsProtocol(*args, **kwargs)
class dynamic_metadata.protocols.DynamicMetadataWheelProtocol(*args, **kwargs)

Field taxonomy

The single source of truth for which [project] fields can be dynamic and what shape their value has.

Plugin helpers

Shared helpers that bundled and third-party plugins can reuse.

Schema

dynamic_metadata.schema.get_schema()
Return type:

dict[str, Any]