Home / File/ _compat.py — anthropic-sdk-python Source File

_compat.py — anthropic-sdk-python Source File

Architecture documentation for _compat.py, a python file in the anthropic-sdk-python codebase. 12 imports, 3 dependents.

File python AnthropicClient SyncAPI 12 imports 3 dependents 17 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  5828b8ae_9c8c_9b95_9f29_d2659004d334["_compat.py"]
  87f621ac_b3e0_a225_72b3_99f9818f3002["_types.py"]
  5828b8ae_9c8c_9b95_9f29_d2659004d334 --> 87f621ac_b3e0_a225_72b3_99f9818f3002
  6dadb144_3070_6111_357f_214554108905["__init__.py"]
  5828b8ae_9c8c_9b95_9f29_d2659004d334 --> 6dadb144_3070_6111_357f_214554108905
  89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"]
  5828b8ae_9c8c_9b95_9f29_d2659004d334 --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875
  7e1d14c5_475e_409c_7c4e_1274f9d40aa9["datetime"]
  5828b8ae_9c8c_9b95_9f29_d2659004d334 --> 7e1d14c5_475e_409c_7c4e_1274f9d40aa9
  37c05070_ca59_d596_7250_de9d1939227f["typing_extensions"]
  5828b8ae_9c8c_9b95_9f29_d2659004d334 --> 37c05070_ca59_d596_7250_de9d1939227f
  21de8837_7dae_989e_fdbb_1415c0770d90["pydantic"]
  5828b8ae_9c8c_9b95_9f29_d2659004d334 --> 21de8837_7dae_989e_fdbb_1415c0770d90
  69b1a279_eb5b_94b8_909b_680c2332e696["pydantic.fields"]
  5828b8ae_9c8c_9b95_9f29_d2659004d334 --> 69b1a279_eb5b_94b8_909b_680c2332e696
  6d75cea4_04d5_3ee7_5e04_51617a9339d6["pydantic.typing"]
  5828b8ae_9c8c_9b95_9f29_d2659004d334 --> 6d75cea4_04d5_3ee7_5e04_51617a9339d6
  92c5c37e_54a6_037a_db37_5176e13529d8["pydantic.datetime_parse"]
  5828b8ae_9c8c_9b95_9f29_d2659004d334 --> 92c5c37e_54a6_037a_db37_5176e13529d8
  ddac56e7_07d6_d714_7f74_b24079c811e7["pydantic_core"]
  5828b8ae_9c8c_9b95_9f29_d2659004d334 --> ddac56e7_07d6_d714_7f74_b24079c811e7
  c6fb595e_8df2_6852_a8c9_c369e325b060["pydantic.generics"]
  5828b8ae_9c8c_9b95_9f29_d2659004d334 --> c6fb595e_8df2_6852_a8c9_c369e325b060
  4c73056b_526d_2199_4a80_7fcd0cd9bcbe["functools"]
  5828b8ae_9c8c_9b95_9f29_d2659004d334 --> 4c73056b_526d_2199_4a80_7fcd0cd9bcbe
  31e60ad8_cac8_652d_176d_4f7cf7dda1ad["_base_client.py"]
  31e60ad8_cac8_652d_176d_4f7cf7dda1ad --> 5828b8ae_9c8c_9b95_9f29_d2659004d334
  3a4e7de9_0222_597c_a697_7ff97bd0dafc["_client.py"]
  3a4e7de9_0222_597c_a697_7ff97bd0dafc --> 5828b8ae_9c8c_9b95_9f29_d2659004d334
  style 5828b8ae_9c8c_9b95_9f29_d2659004d334 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Union, Generic, TypeVar, Callable, cast, overload
from datetime import date, datetime
from typing_extensions import Self, Literal

import pydantic
from pydantic.fields import FieldInfo

from ._types import IncEx, StrBytesIntFloat

_T = TypeVar("_T")
_ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)

# --------------- Pydantic v2, v3 compatibility ---------------

# Pyright incorrectly reports some of our functions as overriding a method when they don't
# pyright: reportIncompatibleMethodOverride=false

PYDANTIC_V1 = pydantic.VERSION.startswith("1.")

if TYPE_CHECKING:

    def parse_date(value: date | StrBytesIntFloat) -> date:  # noqa: ARG001
        ...

    def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime:  # noqa: ARG001
        ...

    def get_args(t: type[Any]) -> tuple[Any, ...]:  # noqa: ARG001
        ...

    def is_union(tp: type[Any] | None) -> bool:  # noqa: ARG001
        ...

    def get_origin(t: type[Any]) -> type[Any] | None:  # noqa: ARG001
        ...

    def is_literal_type(type_: type[Any]) -> bool:  # noqa: ARG001
        ...

    def is_typeddict(type_: type[Any]) -> bool:  # noqa: ARG001
        ...

else:
    # v1 re-exports
    if PYDANTIC_V1:
        from pydantic.typing import (
            get_args as get_args,
            is_union as is_union,
            get_origin as get_origin,
            is_typeddict as is_typeddict,
            is_literal_type as is_literal_type,
        )
        from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
    else:
        from ._utils import (
            get_args as get_args,
            is_union as is_union,
            get_origin as get_origin,
// ... (166 more lines)

Subdomains

Dependencies

  • __init__.py
  • _types.py
  • datetime
  • functools
  • pydantic
  • pydantic.datetime_parse
  • pydantic.fields
  • pydantic.generics
  • pydantic.typing
  • pydantic_core
  • typing
  • typing_extensions

Frequently Asked Questions

What does _compat.py do?
_compat.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, SyncAPI subdomain.
What functions are defined in _compat.py?
_compat.py defines 17 function(s): GenericModel, PYDANTIC_V1, cached_property, field_get_default, field_is_required, field_outer_type, functools, get_model_config, get_model_fields, model_copy, and 7 more.
What does _compat.py depend on?
_compat.py imports 12 module(s): __init__.py, _types.py, datetime, functools, pydantic, pydantic.datetime_parse, pydantic.fields, pydantic.generics, and 4 more.
What files import _compat.py?
_compat.py is imported by 3 file(s): _base_client.py, _client.py, _models.py.
Where is _compat.py in the architecture?
_compat.py is located at src/anthropic/_compat.py (domain: AnthropicClient, subdomain: SyncAPI, directory: src/anthropic).

Analyze Your Own Codebase

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

Try Supermodel Free