Skip to content

responses

EntryInfoResponse

Bases: Success

Source code in optimade/models/responses.py
61
62
63
64
65
class EntryInfoResponse(Success):
    data: Annotated[
        EntryInfoResource,
        StrictField(description="OPTIMADE information for an entry endpoint."),
    ]

data instance-attribute

errors = None class-attribute instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

either_data_meta_or_errors_must_be_set()

Overwriting the existing validation function, since 'errors' MUST NOT be set.

Source code in optimade/models/optimade_json.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Success":
    """Overwriting the existing validation function, since 'errors' MUST NOT be set."""
    required_fields = ("data", "meta")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response."
        )

    # errors MUST be skipped
    if self.errors or "errors" in self.model_fields_set:
        raise ValueError("'errors' MUST be skipped for a successful response.")

    return self

EntryResponseMany

Bases: Success

Source code in optimade/models/responses.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
class EntryResponseMany(Success):
    data: Annotated[  # type: ignore[assignment]
        list[EntryResource] | list[dict[str, Any]],
        StrictField(
            description="List of unique OPTIMADE entry resource objects.",
            uniqueItems=True,
            union_mode="left_to_right",
        ),
    ]
    included: Annotated[
        list[EntryResource] | list[dict[str, Any]] | None,
        StrictField(
            description="A list of unique included OPTIMADE entry resources.",
            uniqueItems=True,
            union_mode="left_to_right",
        ),
    ] = None  # type: ignore[assignment]

data instance-attribute

errors = None class-attribute instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

either_data_meta_or_errors_must_be_set()

Overwriting the existing validation function, since 'errors' MUST NOT be set.

Source code in optimade/models/optimade_json.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Success":
    """Overwriting the existing validation function, since 'errors' MUST NOT be set."""
    required_fields = ("data", "meta")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response."
        )

    # errors MUST be skipped
    if self.errors or "errors" in self.model_fields_set:
        raise ValueError("'errors' MUST be skipped for a successful response.")

    return self

EntryResponseOne

Bases: Success

Source code in optimade/models/responses.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class EntryResponseOne(Success):
    data: Annotated[
        EntryResource | dict[str, Any] | None,
        StrictField(
            description="The single entry resource returned by this query.",
            union_mode="left_to_right",
        ),
    ] = None  # type: ignore[assignment]
    included: Annotated[
        list[EntryResource] | list[dict[str, Any]] | None,
        StrictField(
            description="A list of unique included OPTIMADE entry resources.",
            uniqueItems=True,
            union_mode="left_to_right",
        ),
    ] = None  # type: ignore[assignment]

data = None class-attribute instance-attribute

errors = None class-attribute instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

either_data_meta_or_errors_must_be_set()

Overwriting the existing validation function, since 'errors' MUST NOT be set.

Source code in optimade/models/optimade_json.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Success":
    """Overwriting the existing validation function, since 'errors' MUST NOT be set."""
    required_fields = ("data", "meta")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response."
        )

    # errors MUST be skipped
    if self.errors or "errors" in self.model_fields_set:
        raise ValueError("'errors' MUST be skipped for a successful response.")

    return self

ErrorResponse

Bases: Response

errors MUST be present and data MUST be skipped

Source code in optimade/models/responses.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class ErrorResponse(Response):
    """errors MUST be present and data MUST be skipped"""

    meta: Annotated[
        ResponseMeta,
        StrictField(description="A meta object containing non-standard information."),
    ]
    errors: Annotated[
        list[OptimadeError],
        StrictField(
            description="A list of OPTIMADE-specific JSON API error objects, where the field detail MUST be present.",
            uniqueItems=True,
        ),
    ]

    @model_validator(mode="after")
    def data_must_be_skipped(self) -> "ErrorResponse":
        if self.data or "data" in self.model_fields_set:
            raise ValueError("data MUST be skipped for failures reporting errors.")
        return self

data = None class-attribute instance-attribute

errors instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

data_must_be_skipped()

Source code in optimade/models/responses.py
48
49
50
51
52
@model_validator(mode="after")
def data_must_be_skipped(self) -> "ErrorResponse":
    if self.data or "data" in self.model_fields_set:
        raise ValueError("data MUST be skipped for failures reporting errors.")
    return self

either_data_meta_or_errors_must_be_set()

Source code in optimade/models/jsonapi.py
403
404
405
406
407
408
409
410
411
412
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Response":
    required_fields = ("data", "meta", "errors")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response"
        )
    if "errors" in self.model_fields_set and not self.errors:
        raise ValueError("Errors MUST NOT be an empty or 'null' value.")
    return self

FileResponseMany

Bases: EntryResponseMany

Source code in optimade/models/responses.py
153
154
155
156
157
158
159
160
161
class FileResponseMany(EntryResponseMany):
    data: Annotated[
        list[FileResource] | list[dict[str, Any]],
        StrictField(
            description="List of unique OPTIMADE files entry resource objects.",
            uniqueItems=True,
            union_mode="left_to_right",
        ),
    ]

data instance-attribute

errors = None class-attribute instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

either_data_meta_or_errors_must_be_set()

Overwriting the existing validation function, since 'errors' MUST NOT be set.

Source code in optimade/models/optimade_json.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Success":
    """Overwriting the existing validation function, since 'errors' MUST NOT be set."""
    required_fields = ("data", "meta")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response."
        )

    # errors MUST be skipped
    if self.errors or "errors" in self.model_fields_set:
        raise ValueError("'errors' MUST be skipped for a successful response.")

    return self

FileResponseOne

Bases: EntryResponseOne

Source code in optimade/models/responses.py
143
144
145
146
147
148
149
150
class FileResponseOne(EntryResponseOne):
    data: Annotated[
        FileResource | dict[str, Any] | None,
        StrictField(
            description="A single files entry resource.",
            union_mode="left_to_right",
        ),
    ]

data instance-attribute

errors = None class-attribute instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

either_data_meta_or_errors_must_be_set()

Overwriting the existing validation function, since 'errors' MUST NOT be set.

Source code in optimade/models/optimade_json.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Success":
    """Overwriting the existing validation function, since 'errors' MUST NOT be set."""
    required_fields = ("data", "meta")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response."
        )

    # errors MUST be skipped
    if self.errors or "errors" in self.model_fields_set:
        raise ValueError("'errors' MUST be skipped for a successful response.")

    return self

IndexInfoResponse

Bases: Success

Source code in optimade/models/responses.py
55
56
57
58
class IndexInfoResponse(Success):
    data: Annotated[
        IndexInfoResource, StrictField(description="Index meta-database /info data.")
    ]

data instance-attribute

errors = None class-attribute instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

either_data_meta_or_errors_must_be_set()

Overwriting the existing validation function, since 'errors' MUST NOT be set.

Source code in optimade/models/optimade_json.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Success":
    """Overwriting the existing validation function, since 'errors' MUST NOT be set."""
    required_fields = ("data", "meta")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response."
        )

    # errors MUST be skipped
    if self.errors or "errors" in self.model_fields_set:
        raise ValueError("'errors' MUST be skipped for a successful response.")

    return self

InfoResponse

Bases: Success

Source code in optimade/models/responses.py
68
69
70
71
class InfoResponse(Success):
    data: Annotated[
        BaseInfoResource, StrictField(description="The implementations /info data.")
    ]

data instance-attribute

errors = None class-attribute instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

either_data_meta_or_errors_must_be_set()

Overwriting the existing validation function, since 'errors' MUST NOT be set.

Source code in optimade/models/optimade_json.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Success":
    """Overwriting the existing validation function, since 'errors' MUST NOT be set."""
    required_fields = ("data", "meta")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response."
        )

    # errors MUST be skipped
    if self.errors or "errors" in self.model_fields_set:
        raise ValueError("'errors' MUST be skipped for a successful response.")

    return self

LinksResponse

Bases: EntryResponseMany

Source code in optimade/models/responses.py
111
112
113
114
115
116
117
118
119
class LinksResponse(EntryResponseMany):
    data: Annotated[
        list[LinksResource] | list[dict[str, Any]],
        StrictField(
            description="List of unique OPTIMADE links resource objects.",
            uniqueItems=True,
            union_mode="left_to_right",
        ),
    ]

data instance-attribute

errors = None class-attribute instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

either_data_meta_or_errors_must_be_set()

Overwriting the existing validation function, since 'errors' MUST NOT be set.

Source code in optimade/models/optimade_json.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Success":
    """Overwriting the existing validation function, since 'errors' MUST NOT be set."""
    required_fields = ("data", "meta")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response."
        )

    # errors MUST be skipped
    if self.errors or "errors" in self.model_fields_set:
        raise ValueError("'errors' MUST be skipped for a successful response.")

    return self

ReferenceResponseMany

Bases: EntryResponseMany

Source code in optimade/models/responses.py
174
175
176
177
178
179
180
181
182
class ReferenceResponseMany(EntryResponseMany):
    data: Annotated[
        list[ReferenceResource] | list[dict[str, Any]],
        StrictField(
            description="List of unique OPTIMADE references entry resource objects.",
            uniqueItems=True,
            union_mode="left_to_right",
        ),
    ]

data instance-attribute

errors = None class-attribute instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

either_data_meta_or_errors_must_be_set()

Overwriting the existing validation function, since 'errors' MUST NOT be set.

Source code in optimade/models/optimade_json.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Success":
    """Overwriting the existing validation function, since 'errors' MUST NOT be set."""
    required_fields = ("data", "meta")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response."
        )

    # errors MUST be skipped
    if self.errors or "errors" in self.model_fields_set:
        raise ValueError("'errors' MUST be skipped for a successful response.")

    return self

ReferenceResponseOne

Bases: EntryResponseOne

Source code in optimade/models/responses.py
164
165
166
167
168
169
170
171
class ReferenceResponseOne(EntryResponseOne):
    data: Annotated[
        ReferenceResource | dict[str, Any] | None,
        StrictField(
            description="A single references entry resource.",
            union_mode="left_to_right",
        ),
    ]

data instance-attribute

errors = None class-attribute instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

either_data_meta_or_errors_must_be_set()

Overwriting the existing validation function, since 'errors' MUST NOT be set.

Source code in optimade/models/optimade_json.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Success":
    """Overwriting the existing validation function, since 'errors' MUST NOT be set."""
    required_fields = ("data", "meta")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response."
        )

    # errors MUST be skipped
    if self.errors or "errors" in self.model_fields_set:
        raise ValueError("'errors' MUST be skipped for a successful response.")

    return self

StructureResponseMany

Bases: EntryResponseMany

Source code in optimade/models/responses.py
132
133
134
135
136
137
138
139
140
class StructureResponseMany(EntryResponseMany):
    data: Annotated[
        list[StructureResource] | list[dict[str, Any]],
        StrictField(
            description="List of unique OPTIMADE structures entry resource objects.",
            uniqueItems=True,
            union_mode="left_to_right",
        ),
    ]

data instance-attribute

errors = None class-attribute instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

either_data_meta_or_errors_must_be_set()

Overwriting the existing validation function, since 'errors' MUST NOT be set.

Source code in optimade/models/optimade_json.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Success":
    """Overwriting the existing validation function, since 'errors' MUST NOT be set."""
    required_fields = ("data", "meta")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response."
        )

    # errors MUST be skipped
    if self.errors or "errors" in self.model_fields_set:
        raise ValueError("'errors' MUST be skipped for a successful response.")

    return self

StructureResponseOne

Bases: EntryResponseOne

Source code in optimade/models/responses.py
122
123
124
125
126
127
128
129
class StructureResponseOne(EntryResponseOne):
    data: Annotated[
        StructureResource | dict[str, Any] | None,
        StrictField(
            description="A single structures entry resource.",
            union_mode="left_to_right",
        ),
    ]

data instance-attribute

errors = None class-attribute instance-attribute

included = None class-attribute instance-attribute

jsonapi = None class-attribute instance-attribute

meta instance-attribute

model_config = ConfigDict(json_encoders={datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}) class-attribute instance-attribute

The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.

either_data_meta_or_errors_must_be_set()

Overwriting the existing validation function, since 'errors' MUST NOT be set.

Source code in optimade/models/optimade_json.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@model_validator(mode="after")
def either_data_meta_or_errors_must_be_set(self) -> "Success":
    """Overwriting the existing validation function, since 'errors' MUST NOT be set."""
    required_fields = ("data", "meta")
    if not any(field in self.model_fields_set for field in required_fields):
        raise ValueError(
            f"At least one of {required_fields} MUST be specified in the top-level response."
        )

    # errors MUST be skipped
    if self.errors or "errors" in self.model_fields_set:
        raise ValueError("'errors' MUST be skipped for a successful response.")

    return self