Home / Function/ _format_data() — anthropic-sdk-python Function Reference

_format_data() — anthropic-sdk-python Function Reference

Architecture documentation for the _format_data() function in _transform.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  13e71ee3_9bf3_72c5_fd90_2eff2072c9cd["_format_data()"]
  17ea9c01_2df6_304d_71e2_31af17ed7395["_transform.py"]
  13e71ee3_9bf3_72c5_fd90_2eff2072c9cd -->|defined in| 17ea9c01_2df6_304d_71e2_31af17ed7395
  76cf4787_3c42_ee68_9967_3160c7a1aa0d["_transform_recursive()"]
  76cf4787_3c42_ee68_9967_3160c7a1aa0d -->|calls| 13e71ee3_9bf3_72c5_fd90_2eff2072c9cd
  style 13e71ee3_9bf3_72c5_fd90_2eff2072c9cd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/_utils/_transform.py lines 236–260

def _format_data(data: object, format_: PropertyFormat, format_template: str | None) -> object:
    if isinstance(data, (date, datetime)):
        if format_ == "iso8601":
            return data.isoformat()

        if format_ == "custom" and format_template is not None:
            return data.strftime(format_template)

    if format_ == "base64" and is_base64_file_input(data):
        binary: str | bytes | None = None

        if isinstance(data, pathlib.Path):
            binary = data.read_bytes()
        elif isinstance(data, io.IOBase):
            binary = data.read()

            if isinstance(binary, str):  # type: ignore[unreachable]
                binary = binary.encode()

        if not isinstance(binary, bytes):
            raise RuntimeError(f"Could not read bytes from {data}; Received {type(binary)}")

        return base64.b64encode(binary).decode("ascii")

    return data

Subdomains

Frequently Asked Questions

What does _format_data() do?
_format_data() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/_utils/_transform.py.
Where is _format_data() defined?
_format_data() is defined in src/anthropic/_utils/_transform.py at line 236.
What calls _format_data()?
_format_data() is called by 1 function(s): _transform_recursive.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free