Module adcp.utils
Sub-modules
adcp.utils.format_assets-
Format Asset Utilities …
adcp.utils.operation_idadcp.utils.preview_cache-
Helper utilities for generating creative preview URLs for grid rendering.
adcp.utils.response_parser
Functions
def create_operation_id() ‑> str-
Expand source code
def create_operation_id() -> str: """ Generate a unique operation ID. Returns: A unique operation ID in the format 'op_{hex}' """ return f"op_{uuid4().hex[:12]}"Generate a unique operation ID.
Returns -----= A unique operation ID in the format 'op_{hex}'
def get_asset_count(format: FormatAssetsInput | Mapping[str, Any]) ‑> int-
Expand source code
def get_asset_count(format: FormatAssetsInput | Mapping[str, Any]) -> int: """Get the count of assets in a format (for display purposes). Args: format: The Format object Returns: Number of assets, or 0 if none defined """ return len(get_format_assets(format))Get the count of assets in a format (for display purposes).
- Args
- -----=
format- The Format object
Returns -----= Number of assets, or 0 if none defined
def get_format_assets(format: FormatAssetsInput | Mapping[str, Any]) ‑> list[typing.Any]-
Expand source code
def get_format_assets(format: FormatAssetsInput | Mapping[str, Any]) -> list[FormatAsset]: """Get assets from a Format. Returns the list of assets from the format's `assets` field. Returns empty list if no assets are defined (flexible format with no assets). Args: format: Any canonical declaration or raw catalog object exposing ``assets`` Returns: List of assets Example: ```python for declaration in product.format_options: assets = get_format_assets(declaration) print(f"{declaration.format_kind} has {len(assets)} assets") ``` """ if isinstance(format, Mapping): assets = format.get("assets") if assets is None and isinstance(format.get("params"), Mapping): assets = format["params"].get("slots") else: assets = getattr(format, "assets", None) if assets is None: params = getattr(format, "params", None) assets = params.get("slots") if isinstance(params, Mapping) else None if assets: return list(assets) return []Get assets from a Format.
Returns the list of assets from the format's
assetsfield. Returns empty list if no assets are defined (flexible format with no assets).- Args
- -----=
format- Any canonical declaration or raw catalog object exposing
assets
Returns -----= List of assets
Example -----=
for declaration in product.format_options: assets = get_format_assets(declaration) print(f"{declaration.format_kind} has {len(assets)} assets") def get_individual_assets(format: FormatAssetsInput | Mapping[str, Any]) ‑> list[typing.Any]-
Expand source code
def get_individual_assets(format: FormatAssetsInput | Mapping[str, Any]) -> list[FormatAsset]: """Get individual assets (not repeatable groups) from a Format. Args: format: The Format object Returns: List of individual assets (item_type='individual') """ return [asset for asset in get_format_assets(format) if _get_item_type(asset) == "individual"]Get individual assets (not repeatable groups) from a Format.
- Args
- -----=
format- The Format object
Returns -----= List of individual assets (item_type='individual')
def get_optional_assets(format: FormatAssetsInput | Mapping[str, Any]) ‑> list[typing.Any]-
Expand source code
def get_optional_assets(format: FormatAssetsInput | Mapping[str, Any]) -> list[FormatAsset]: """Get only optional assets from a Format. Note: When using deprecated `assets_required`, this will always return empty since assets_required only contained required assets. Args: format: The Format object Returns: List of optional assets only Example: ```python optional_assets = get_optional_assets(format) print(f"Can optionally provide {len(optional_assets)} additional assets") ``` """ return [asset for asset in get_format_assets(format) if not _is_required(asset)]Get only optional assets from a Format.
Note: When using deprecated
assets_required, this will always return empty since assets_required only contained required assets.- Args
- -----=
format- The Format object
Returns -----= List of optional assets only
Example -----=
optional_assets = get_optional_assets(format) print(f"Can optionally provide {len(optional_assets)} additional assets") def get_repeatable_groups(format: FormatAssetsInput | Mapping[str, Any]) ‑> list[typing.Any]-
Expand source code
def get_repeatable_groups(format: FormatAssetsInput | Mapping[str, Any]) -> list[FormatAsset]: """Get repeatable asset groups from a Format. Args: format: The Format object Returns: List of repeatable asset groups (item_type='repeatable_group') """ return [ asset for asset in get_format_assets(format) if _get_item_type(asset) == "repeatable_group" ]Get repeatable asset groups from a Format.
- Args
- -----=
format- The Format object
Returns -----= List of repeatable asset groups (item_type='repeatable_group')
def get_required_assets(format: FormatAssetsInput | Mapping[str, Any]) ‑> list[typing.Any]-
Expand source code
def get_required_assets(format: FormatAssetsInput | Mapping[str, Any]) -> list[FormatAsset]: """Get only required assets from a Format. Args: format: The Format object Returns: List of required assets only Example: ```python required_assets = get_required_assets(format) print(f"Must provide {len(required_assets)} assets") ``` """ return [asset for asset in get_format_assets(format) if _is_required(asset)]Get only required assets from a Format.
- Args
- -----=
format- The Format object
Returns -----= List of required assets only
Example -----=
required_assets = get_required_assets(format) print(f"Must provide {len(required_assets)} assets") def has_assets(format: FormatAssetsInput | Mapping[str, Any]) ‑> bool-
Expand source code
def has_assets(format: FormatAssetsInput | Mapping[str, Any]) -> bool: """Check if a format has any assets defined. Args: format: The Format object Returns: True if format has assets, False otherwise """ return get_asset_count(format) > 0Check if a format has any assets defined.
- Args
- -----=
format- The Format object
Returns -----= True if format has assets, False otherwise
def normalize_assets_required(assets_required: list[Any]) ‑> list[typing.Any]-
Expand source code
def normalize_assets_required(assets_required: list[Any]) -> list[FormatAsset]: """Convert deprecated assets_required to new assets format. .. deprecated:: 3.2.0 The ``assets_required`` field was removed in ADCP 3.0.0-beta.2. This function will be removed in a future version. All assets in assets_required are required by definition (that's why they were in that array). The new `assets` field has an explicit `required: boolean` to allow both required AND optional assets. Args: assets_required: The deprecated assets_required array Returns: Normalized assets as Pydantic models with explicit required=True """ warnings.warn( "normalize_assets_required() is deprecated. " "The assets_required field was removed in ADCP 3.0.0-beta.2. " "This function will be removed in a future version.", DeprecationWarning, stacklevel=2, ) normalized: list[FormatAsset] = [] for asset in assets_required: # Get asset data as dict if isinstance(asset, dict): asset_dict = asset else: asset_dict = asset.model_dump() if hasattr(asset, "model_dump") else dict(asset) # Map old fields to new schema format mapped = {**asset_dict, "required": True} # Ensure asset_id is present (map from asset_group_id if needed) if "asset_group_id" in mapped and "asset_id" not in mapped: mapped["asset_id"] = mapped.pop("asset_group_id") # Remove fields that don't exist in the new schema for old_field in ("min_count", "max_count", "assets"): mapped.pop(old_field, None) # Use AssetsModel (individual asset type) normalized.append(AssetsModel(**mapped)) return normalizedConvert deprecated assets_required to new assets format.
Deprecated since version: 3.2.0
The
assets_requiredfield was removed in ADCP 3.0.0-beta.2. This function will be removed in a future version.All assets in assets_required are required by definition (that's why they were in that array). The new
assetsfield has an explicitrequired: booleanto allow both required AND optional assets.- Args
- -----=
assets_required- The deprecated assets_required array
Returns -----= Normalized assets as Pydantic models with explicit required=True
def uses_deprecated_assets_field(format: FormatAssetsInput | Mapping[str, Any]) ‑> bool-
Expand source code
def uses_deprecated_assets_field(format: FormatAssetsInput | Mapping[str, Any]) -> bool: """Check if format uses deprecated assets_required field. .. deprecated:: 3.2.0 The ``assets_required`` field was removed in ADCP 3.0.0-beta.2. This function always returns False and will be removed in a future version. Args: format: The Format object Returns: Always False (deprecated field no longer exists) """ warnings.warn( "uses_deprecated_assets_field() is deprecated and always returns False. " "The assets_required field was removed in ADCP 3.0.0-beta.2. " "This function will be removed in a future version.", DeprecationWarning, stacklevel=2, ) return FalseCheck if format uses deprecated assets_required field.
Deprecated since version: 3.2.0
The
assets_requiredfield was removed in ADCP 3.0.0-beta.2. This function always returns False and will be removed in a future version.- Args
- -----=
format- The Format object
Returns -----= Always False (deprecated field no longer exists)
Classes
class CanonicalFormatAssetsInput (*args, **kwargs)-
Expand source code
class CanonicalFormatAssetsInput(Protocol): """Canonical declaration view whose slots live under ``params``.""" params: Mapping[str, Any]Canonical declaration view whose slots live under
params.Ancestors
- typing.Protocol
- typing.Generic
Class variables
var params : Mapping[str, typing.Any]
class LegacyFormatAssetsInput (*args, **kwargs)-
Expand source code
class LegacyFormatAssetsInput(Protocol): """Raw catalog view accepted by identity-free asset-slot helpers.""" assets: Sequence[Any] | NoneRaw catalog view accepted by identity-free asset-slot helpers.
Ancestors
- typing.Protocol
- typing.Generic
Class variables
var assets : collections.abc.Sequence[typing.Any] | None