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

_maybe_transform_key() — anthropic-sdk-python Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  7dd9f3f8_e9d3_eb28_5171_d0dd7a1780c9["_maybe_transform_key()"]
  17ea9c01_2df6_304d_71e2_31af17ed7395["_transform.py"]
  7dd9f3f8_e9d3_eb28_5171_d0dd7a1780c9 -->|defined in| 17ea9c01_2df6_304d_71e2_31af17ed7395
  73674319_0076_f928_202c_b195fd052f6b["_transform_typeddict()"]
  73674319_0076_f928_202c_b195fd052f6b -->|calls| 7dd9f3f8_e9d3_eb28_5171_d0dd7a1780c9
  15bcb228_a48d_a6a6_e8ae_a9233b3a1bae["_async_transform_typeddict()"]
  15bcb228_a48d_a6a6_e8ae_a9233b3a1bae -->|calls| 7dd9f3f8_e9d3_eb28_5171_d0dd7a1780c9
  cddc6b7f_09e8_3fbf_4baf_79e4d78b50f9["_get_annotated_type()"]
  7dd9f3f8_e9d3_eb28_5171_d0dd7a1780c9 -->|calls| cddc6b7f_09e8_3fbf_4baf_79e4d78b50f9
  a81fb697_e7fd_351f_22da_edb95ea267b6["get_args()"]
  7dd9f3f8_e9d3_eb28_5171_d0dd7a1780c9 -->|calls| a81fb697_e7fd_351f_22da_edb95ea267b6
  style 7dd9f3f8_e9d3_eb28_5171_d0dd7a1780c9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/_utils/_transform.py lines 131–147

def _maybe_transform_key(key: str, type_: type) -> str:
    """Transform the given `data` based on the annotations provided in `type_`.

    Note: this function only looks at `Annotated` types that contain `PropertyInfo` metadata.
    """
    annotated_type = _get_annotated_type(type_)
    if annotated_type is None:
        # no `Annotated` definition for this type, no transformation needed
        return key

    # ignore the first argument as it is the actual type
    annotations = get_args(annotated_type)[1:]
    for annotation in annotations:
        if isinstance(annotation, PropertyInfo) and annotation.alias is not None:
            return annotation.alias

    return key

Subdomains

Frequently Asked Questions

What does _maybe_transform_key() do?
_maybe_transform_key() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/_utils/_transform.py.
Where is _maybe_transform_key() defined?
_maybe_transform_key() is defined in src/anthropic/_utils/_transform.py at line 131.
What does _maybe_transform_key() call?
_maybe_transform_key() calls 2 function(s): _get_annotated_type, get_args.
What calls _maybe_transform_key()?
_maybe_transform_key() is called by 2 function(s): _async_transform_typeddict, _transform_typeddict.

Analyze Your Own Codebase

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

Try Supermodel Free