schemas¶
ENTRY_INFO_SCHEMAS: dict[str, type[EntryResource]] = {'structures': StructureResource, 'references': ReferenceResource}
module-attribute
¶
This dictionary is used to define the /info/<entry_type>
endpoints.
ERROR_RESPONSES: Optional[dict[int, dict[str, Any]]] = {err.status_code: {'model': ErrorResponse, 'description': err.title}for err in POSSIBLE_ERRORS}
module-attribute
¶
NoneType = type(None)
module-attribute
¶
POSSIBLE_ERRORS: tuple[type[OptimadeHTTPException], ...] = (BadRequest, Forbidden, NotFound, UnprocessableEntity, InternalServerError, NotImplementedResponse, VersionNotSupported)
module-attribute
¶
QueryableProperties = dict[str, dict[Literal['description', 'unit', 'queryable', 'support', 'sortable', 'type'], Optional[Union[str, SupportLevel, bool, DataType]]]]
module-attribute
¶
__all__ = ('ENTRY_INFO_SCHEMAS', 'ERROR_RESPONSES', 'retrieve_queryable_properties')
module-attribute
¶
DataType
¶
Bases: Enum
Optimade Data types
See the section "Data types" in the OPTIMADE API specification for more information.
Source code in optimade/models/optimade_json.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
from_json_type(json_type)
classmethod
¶
Get OPTIMADE data type from a named JSON type
Source code in optimade/models/optimade_json.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
from_python_type(python_type)
classmethod
¶
Get OPTIMADE data type from a Python type
Source code in optimade/models/optimade_json.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
get_values()
classmethod
¶
Get OPTIMADE data types (enum values) as a (sorted) list
Source code in optimade/models/optimade_json.py
43 44 45 46 |
|
EntryResource
¶
Bases: Resource
The base model for an entry resource.
Source code in optimade/models/entries.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
ErrorResponse
¶
Bases: Response
errors MUST be present and data MUST be skipped
Source code in optimade/models/responses.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
model_config = ConfigDict(json_encoders={datetime: lambda : 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.
ReferenceResource
¶
Bases: EntryResource
The references
entries describe bibliographic references.
The following properties are used to provide the bibliographic details:
- address, annote, booktitle, chapter, crossref, edition, howpublished, institution, journal, key, month, note, number, organization, pages, publisher, school, series, title, volume, year: meanings of these properties match the BibTeX specification, values are strings;
- bib_type: type of the reference, corresponding to type property in the BibTeX specification, value is string;
- authors and editors: lists of person objects which are dictionaries with the following keys:
- name: Full name of the person, REQUIRED.
- firstname, lastname: Parts of the person's name, OPTIONAL.
- doi and url: values are strings.
- Requirements/Conventions:
- Support: OPTIONAL support in implementations, i.e., any of the properties MAY be
null
. - Query: Support for queries on any of these properties is OPTIONAL. If supported, filters MAY support only a subset of comparison operators.
- Every references entry MUST contain at least one of the properties.
- Support: OPTIONAL support in implementations, i.e., any of the properties MAY be
Source code in optimade/models/references.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
StructureResource
¶
Bases: EntryResource
Representing a structure.
Source code in optimade/models/structures.py
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 |
|
SupportLevel
¶
Bases: Enum
OPTIMADE property/field support levels
Source code in optimade/models/utils.py
31 32 33 34 35 36 |
|
_get_origin_type(annotation)
¶
Get the origin type of a type annotation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation |
type
|
The type annotation. |
required |
Returns:
Type | Description |
---|---|
type
|
The origin type. |
Source code in optimade/models/types.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
retrieve_queryable_properties(schema, queryable_properties=None, entry_type=None)
¶
Recursively loops through a pydantic model, returning a dictionary of all the OPTIMADE-queryable properties of that model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema |
type[EntryResource]
|
The pydantic model. |
required |
queryable_properties |
Optional[Iterable[str]]
|
The list of properties to find in the schema. |
None
|
entry_type |
Optional[str]
|
An optional entry type for the model. Will be used to lookup schemas for any config-defined fields. |
None
|
Returns:
Type | Description |
---|---|
QueryableProperties
|
A flat dictionary with properties as keys, containing the field |
QueryableProperties
|
description, unit, sortability, support level, queryability |
QueryableProperties
|
and type, where provided. |
Source code in optimade/server/schemas.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|