utils.py — anthropic-sdk-python Source File
Architecture documentation for utils.py, a python file in the anthropic-sdk-python codebase. 11 imports, 11 dependents.
Entity Profile
Dependency Diagram
graph LR cf46c35e_ae7e_a652_f32b_5dd703f4d658["utils.py"] bb0af148_44a9_df40_49c4_0fa6ceb5a403["os"] cf46c35e_ae7e_a652_f32b_5dd703f4d658 --> bb0af148_44a9_df40_49c4_0fa6ceb5a403 506d0594_2a0d_4f14_1041_ed428dcfcac8["inspect"] cf46c35e_ae7e_a652_f32b_5dd703f4d658 --> 506d0594_2a0d_4f14_1041_ed428dcfcac8 8a9a7aeb_dc9d_5e5a_6375_2090f4340983["traceback"] cf46c35e_ae7e_a652_f32b_5dd703f4d658 --> 8a9a7aeb_dc9d_5e5a_6375_2090f4340983 c98b2067_811f_0505_6d3f_bde955212221["contextlib"] cf46c35e_ae7e_a652_f32b_5dd703f4d658 --> c98b2067_811f_0505_6d3f_bde955212221 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"] cf46c35e_ae7e_a652_f32b_5dd703f4d658 --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875 7e1d14c5_475e_409c_7c4e_1274f9d40aa9["datetime"] cf46c35e_ae7e_a652_f32b_5dd703f4d658 --> 7e1d14c5_475e_409c_7c4e_1274f9d40aa9 37c05070_ca59_d596_7250_de9d1939227f["typing_extensions"] cf46c35e_ae7e_a652_f32b_5dd703f4d658 --> 37c05070_ca59_d596_7250_de9d1939227f 01a140e6_b92b_0f78_5c02_ede12a95cdde["anthropic._types"] cf46c35e_ae7e_a652_f32b_5dd703f4d658 --> 01a140e6_b92b_0f78_5c02_ede12a95cdde d1009234_f799_7c53_7892_4262523206dd["anthropic._utils"] cf46c35e_ae7e_a652_f32b_5dd703f4d658 --> d1009234_f799_7c53_7892_4262523206dd 42bc4048_b76c_4d27_9cbe_884618df8c52["anthropic._compat"] cf46c35e_ae7e_a652_f32b_5dd703f4d658 --> 42bc4048_b76c_4d27_9cbe_884618df8c52 7d132c4d_8665_7d6c_3d3d_3b1d1f22b9eb["anthropic._models"] cf46c35e_ae7e_a652_f32b_5dd703f4d658 --> 7d132c4d_8665_7d6c_3d3d_3b1d1f22b9eb 8338a118_0daa_4bed_30d9_2d313e1f3766["test_batches.py"] 8338a118_0daa_4bed_30d9_2d313e1f3766 --> cf46c35e_ae7e_a652_f32b_5dd703f4d658 f855b303_fe65_db92_5ad8_65ddc98de902["test_versions.py"] f855b303_fe65_db92_5ad8_65ddc98de902 --> cf46c35e_ae7e_a652_f32b_5dd703f4d658 77116c0e_54b9_67e7_5819_f7c2a135ea20["test_files.py"] 77116c0e_54b9_67e7_5819_f7c2a135ea20 --> cf46c35e_ae7e_a652_f32b_5dd703f4d658 style cf46c35e_ae7e_a652_f32b_5dd703f4d658 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from __future__ import annotations
import os
import inspect
import traceback
import contextlib
from typing import Any, TypeVar, Iterator, Sequence, cast
from datetime import date, datetime
from typing_extensions import Literal, get_args, get_origin, assert_type
from anthropic._types import Omit, NoneType
from anthropic._utils import (
is_dict,
is_list,
is_list_type,
is_union_type,
extract_type_arg,
is_sequence_type,
is_annotated_type,
is_type_alias_type,
)
from anthropic._compat import PYDANTIC_V1, field_outer_type, get_model_fields
from anthropic._models import BaseModel
BaseModelT = TypeVar("BaseModelT", bound=BaseModel)
def assert_matches_model(model: type[BaseModelT], value: BaseModelT, *, path: list[str]) -> bool:
for name, field in get_model_fields(model).items():
field_value = getattr(value, name)
if PYDANTIC_V1:
# in v1 nullability was structured differently
# https://docs.pydantic.dev/2.0/migration/#required-optional-and-nullable-fields
allow_none = getattr(field, "allow_none", False)
else:
allow_none = False
assert_matches_type(
field_outer_type(field),
field_value,
path=[*path, name],
allow_none=allow_none,
)
return True
# Note: the `path` argument is only used to improve error messages when `--showlocals` is used
def assert_matches_type(
type_: Any,
value: object,
*,
path: list[str],
allow_none: bool = False,
) -> None:
if is_type_alias_type(type_):
type_ = type_.__value__
# unwrap `Annotated[T, ...]` -> `T`
if is_annotated_type(type_):
// ... (108 more lines)
Domain
Subdomains
Dependencies
- anthropic._compat
- anthropic._models
- anthropic._types
- anthropic._utils
- contextlib
- datetime
- inspect
- os
- traceback
- typing
- typing_extensions
Imported By
- tests/api_resources/beta/messages/test_batches.py
- tests/api_resources/messages/test_batches.py
- tests/test_client.py
- tests/api_resources/test_completions.py
- tests/api_resources/beta/test_files.py
- tests/api_resources/beta/test_messages.py
- tests/api_resources/test_messages.py
- tests/api_resources/beta/test_models.py
- tests/api_resources/test_models.py
- tests/api_resources/beta/test_skills.py
- tests/api_resources/beta/skills/test_versions.py
Source
Frequently Asked Questions
What does utils.py do?
utils.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, AsyncAPI subdomain.
What functions are defined in utils.py?
utils.py defines 4 function(s): _assert_list_type, assert_matches_model, assert_matches_type, update_env.
What does utils.py depend on?
utils.py imports 11 module(s): anthropic._compat, anthropic._models, anthropic._types, anthropic._utils, contextlib, datetime, inspect, os, and 3 more.
What files import utils.py?
utils.py is imported by 11 file(s): test_batches.py, test_batches.py, test_client.py, test_completions.py, test_files.py, test_messages.py, test_messages.py, test_models.py, and 3 more.
Where is utils.py in the architecture?
utils.py is located at tests/utils.py (domain: AnthropicClient, subdomain: AsyncAPI, directory: tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free