from __future__ import annotations from collections.abc import Iterable from copy import deepcopy from typing import Any def with_raw_payload( record: dict[str, Any], *, exclude_keys: Iterable[str] = (), ) -> dict[str, Any]: excluded = {"raw_payload", *exclude_keys} payload = {key: deepcopy(value) for key, value in record.items() if key not in excluded} return {**record, "raw_payload": payload}