Skip to content

Config Coercion

Shared constructor and process-config coercion for media toolkit processors.

coerce_config hydrates a stable constructor model. merge_process_config overlays per-call process_config fields (None means “keep constructor”) and returns the same constructor model type.

coerce_config(config, model)

Coerce a constructor config dict / model / None into model.

Shared family configs (parent BaseModel instances that are not the exact backend model) are re-validated so backend-specific defaults fill in.

Parameters:

Name Type Description Default
config dict[str, Any] | BaseModel | None

A dict to hydrate, a model instance, or None for defaults.

required
model type[TModel]

Target constructor config class.

required

Returns:

Name Type Description
TModel TModel

A typed config instance of model.

Raises:

Type Description
TypeError

If config is neither dict, BaseModel, nor None.

coerce_optional_process_config(process_config, model_cls, *, allow_family=False)

Normalize an optional per-invocation process config.

Parameters:

Name Type Description Default
process_config ProcessorProcessConfig | dict[str, Any] | None

Per-call config, a dict to hydrate, or None.

required
model_cls type[TProcess]

Backend process-config class.

required
allow_family bool

When True, parent family process configs are re-validated into model_cls. When False, a parent instance raises. Defaults to False.

False

Returns:

Type Description
TProcess | None

TProcess | None: None when omitted; otherwise a model_cls instance.

Raises:

Type Description
TypeError

If process_config is an unsupported type, or a family instance when allow_family is False.

merge_process_config(stable, process_config, *, process_model, exclude_keys=frozenset(), field_map=None)

Overlay non-None process-config fields onto stable.

Parameters:

Name Type Description Default
stable TModel

Constructor config to start from.

required
process_config ProcessorProcessConfig | dict[str, Any] | None

Per-call overrides. None returns stable unchanged.

required
process_model type[TProcess]

Backend process-config class.

required
exclude_keys frozenset[str]

Process-config keys skipped during the overlay. Defaults to empty.

frozenset()
field_map Mapping[str, str] | None

Copy process-config src onto stable key dest (e.g. timestamps → default_timestamps). Defaults to None.

None

Returns:

Name Type Description
TModel TModel

Effective constructor config of the same type as stable.

Raises:

Type Description
TypeError

If process_config cannot be coerced to process_model.