construct() — anthropic-sdk-python Function Reference
Architecture documentation for the construct() function in _models.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 57e8da7b_af31_35a8_78f7_c274f7fbb350["construct()"] 17ce5647_6f06_0676_a4a5_e378a3f57cb1["BaseModel"] 57e8da7b_af31_35a8_78f7_c274f7fbb350 -->|defined in| 17ce5647_6f06_0676_a4a5_e378a3f57cb1 4e74c968_63fc_ca6c_ccf4_c01326e7060e["construct()"] 4e74c968_63fc_ca6c_ccf4_c01326e7060e -->|calls| 57e8da7b_af31_35a8_78f7_c274f7fbb350 6a04a9a3_665a_b4ac_5fcf_8eaa429b5f9d["get_api_list()"] 6a04a9a3_665a_b4ac_5fcf_8eaa429b5f9d -->|calls| 57e8da7b_af31_35a8_78f7_c274f7fbb350 1f1fa4b5_5943_136f_2cef_23465a8f7aee["construct_type()"] 1f1fa4b5_5943_136f_2cef_23465a8f7aee -->|calls| 57e8da7b_af31_35a8_78f7_c274f7fbb350 4e74c968_63fc_ca6c_ccf4_c01326e7060e["construct()"] 57e8da7b_af31_35a8_78f7_c274f7fbb350 -->|calls| 4e74c968_63fc_ca6c_ccf4_c01326e7060e 6547057f_bf4c_5c68_b343_169004d3f364["get_model_config()"] 57e8da7b_af31_35a8_78f7_c274f7fbb350 -->|calls| 6547057f_bf4c_5c68_b343_169004d3f364 afc80c40_7ec9_e8a7_8063_f2ab74bc2ee7["get()"] 57e8da7b_af31_35a8_78f7_c274f7fbb350 -->|calls| afc80c40_7ec9_e8a7_8063_f2ab74bc2ee7 3342790d_5f26_0380_3f01_b7090b8d3e53["get_model_fields()"] 57e8da7b_af31_35a8_78f7_c274f7fbb350 -->|calls| 3342790d_5f26_0380_3f01_b7090b8d3e53 f18cfc0d_b1d8_c1ad_81bd_c1f4634e0a56["_construct_field()"] 57e8da7b_af31_35a8_78f7_c274f7fbb350 -->|calls| f18cfc0d_b1d8_c1ad_81bd_c1f4634e0a56 287a655c_6822_3e48_42ec_702043f95bb8["field_get_default()"] 57e8da7b_af31_35a8_78f7_c274f7fbb350 -->|calls| 287a655c_6822_3e48_42ec_702043f95bb8 1f3d71e8_e87a_ef4b_aa3d_66605c49e5bd["_get_extra_fields_type()"] 57e8da7b_af31_35a8_78f7_c274f7fbb350 -->|calls| 1f3d71e8_e87a_ef4b_aa3d_66605c49e5bd 1f1fa4b5_5943_136f_2cef_23465a8f7aee["construct_type()"] 57e8da7b_af31_35a8_78f7_c274f7fbb350 -->|calls| 1f1fa4b5_5943_136f_2cef_23465a8f7aee style 57e8da7b_af31_35a8_78f7_c274f7fbb350 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/anthropic/_models.py lines 211–268
def construct( # pyright: ignore[reportIncompatibleMethodOverride]
__cls: Type[ModelT],
_fields_set: set[str] | None = None,
**values: object,
) -> ModelT:
m = __cls.__new__(__cls)
fields_values: dict[str, object] = {}
config = get_model_config(__cls)
populate_by_name = (
config.allow_population_by_field_name
if isinstance(config, _ConfigProtocol)
else config.get("populate_by_name")
)
if _fields_set is None:
_fields_set = set()
model_fields = get_model_fields(__cls)
for name, field in model_fields.items():
key = field.alias
if key is None or (key not in values and populate_by_name):
key = name
if key in values:
fields_values[name] = _construct_field(value=values[key], field=field, key=key)
_fields_set.add(name)
else:
fields_values[name] = field_get_default(field)
extra_field_type = _get_extra_fields_type(__cls)
_extra = {}
for key, value in values.items():
if key not in model_fields:
parsed = construct_type(value=value, type_=extra_field_type) if extra_field_type is not None else value
if PYDANTIC_V1:
_fields_set.add(key)
fields_values[key] = parsed
else:
_extra[key] = parsed
object.__setattr__(m, "__dict__", fields_values)
if PYDANTIC_V1:
# init_private_attributes() does not exist in v2
m._init_private_attributes() # type: ignore
# copied from Pydantic v1's `construct()` method
object.__setattr__(m, "__fields_set__", _fields_set)
else:
# these properties are copied from Pydantic's `model_construct()` method
object.__setattr__(m, "__pydantic_private__", None)
object.__setattr__(m, "__pydantic_extra__", _extra)
object.__setattr__(m, "__pydantic_fields_set__", _fields_set)
return m
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does construct() do?
construct() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/_models.py.
Where is construct() defined?
construct() is defined in src/anthropic/_models.py at line 211.
What does construct() call?
construct() calls 8 function(s): _construct_field, _get_extra_fields_type, construct, construct_type, field_get_default, get, get_model_config, get_model_fields.
What calls construct()?
construct() is called by 3 function(s): construct, construct_type, get_api_list.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free