queries¶
Pydantic models/schemas for the Queries resource.
QUERY_PARAMETERS: QueryParameters = {'annotations': {name: FieldInfo.from_annotation(parameter.annotation)for (name, parameter) in inspect.signature(EntryListingQueryParams).parameters.items()}, 'defaults': EntryListingQueryParams()}
module-attribute
¶
Entry listing URL query parameters from the optimade
package
(EntryListingQueryParams
).
EndpointEntryType
¶
Bases: Enum
Entry endpoint resource types, mapping to their pydantic models from the
optimade
package.
Source code in optimade_gateway/models/queries.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 |
|
REFERENCES = 'references'
class-attribute
instance-attribute
¶
STRUCTURES = 'structures'
class-attribute
instance-attribute
¶
get_resource_model()
¶
Get the matching pydantic model for a resource.
Source code in optimade_gateway/models/queries.py
55 56 57 58 59 60 |
|
get_response_model(single=False)
¶
Get the matching pydantic model for a successful response.
Source code in optimade_gateway/models/queries.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
EntryResource
¶
Bases: EntryResource
Entry Resource ensuring datetimes are not naive.
Source code in optimade_gateway/models/queries.py
210 211 212 213 214 215 216 217 218 219 220 221 |
|
ensure_non_naive_datetime(value)
classmethod
¶
Set timezone to UTC if datetime is naive.
Source code in optimade_gateway/models/queries.py
213 214 215 216 217 218 219 220 221 |
|
GatewayQueryResponse
¶
Bases: Response
Response from a Gateway Query.
Source code in optimade_gateway/models/queries.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
data: Annotated[dict[str, list[EntryResource] | list[dict[str, Any]]], StrictField(uniqueItems=True, description='Outputted Data.')]
instance-attribute
¶
errors: Annotated[list[OptimadeError] | None, StrictField(description='A list of OPTIMADE-specific JSON API error objects, where the field detail MUST be present.', uniqueItems=True)] = []
class-attribute
instance-attribute
¶
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
class-attribute
instance-attribute
¶
meta: Annotated[ResponseMeta, StrictField(description='A meta object containing non-standard information.')]
instance-attribute
¶
either_data_meta_or_errors_must_be_set()
¶
Overwrite either_data_meta_or_errors_must_be_set
.
errors
should be allowed to be present always for this special response.
Source code in optimade_gateway/models/queries.py
257 258 259 260 261 262 263 |
|
OptimadeQueryParameters
¶
Bases: BaseModel
Common OPTIMADE entry listing endpoint query parameters.
Source code in optimade_gateway/models/queries.py
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 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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
api_hint: Annotated[str | None, Field(description=QUERY_PARAMETERS['annotations']['api_hint'].description, pattern=QUERY_PARAMETERS['annotations']['api_hint'].metadata[0].pattern)] = QUERY_PARAMETERS['defaults'].api_hint
class-attribute
instance-attribute
¶
email_address: Annotated[EmailStr | None, Field(description=QUERY_PARAMETERS['annotations']['email_address'].description)] = QUERY_PARAMETERS['defaults'].email_address
class-attribute
instance-attribute
¶
filter: Annotated[str | None, Field(description=QUERY_PARAMETERS['annotations']['filter'].description)] = QUERY_PARAMETERS['defaults'].filter
class-attribute
instance-attribute
¶
include: Annotated[str | None, Field(description=QUERY_PARAMETERS['annotations']['include'].description)] = QUERY_PARAMETERS['defaults'].include
class-attribute
instance-attribute
¶
page_above: Annotated[int | None, Field(description=QUERY_PARAMETERS['annotations']['page_above'].description)] = QUERY_PARAMETERS['defaults'].page_above
class-attribute
instance-attribute
¶
page_below: Annotated[int | None, Field(description=QUERY_PARAMETERS['annotations']['page_below'].description)] = QUERY_PARAMETERS['defaults'].page_below
class-attribute
instance-attribute
¶
page_cursor: Annotated[int | None, Field(description=QUERY_PARAMETERS['annotations']['page_cursor'].description, ge=QUERY_PARAMETERS['annotations']['page_cursor'].metadata[0].ge)] = QUERY_PARAMETERS['defaults'].page_cursor
class-attribute
instance-attribute
¶
page_limit: Annotated[int | None, Field(description=QUERY_PARAMETERS['annotations']['page_limit'].description, ge=QUERY_PARAMETERS['annotations']['page_limit'].metadata[0].ge)] = QUERY_PARAMETERS['defaults'].page_limit
class-attribute
instance-attribute
¶
page_number: Annotated[int | None, Field(description=QUERY_PARAMETERS['annotations']['page_number'].description)] = QUERY_PARAMETERS['defaults'].page_number
class-attribute
instance-attribute
¶
page_offset: Annotated[int | None, Field(description=QUERY_PARAMETERS['annotations']['page_offset'].description, ge=QUERY_PARAMETERS['annotations']['page_offset'].metadata[0].ge)] = QUERY_PARAMETERS['defaults'].page_offset
class-attribute
instance-attribute
¶
response_fields: Annotated[str | None, Field(description=QUERY_PARAMETERS['annotations']['response_fields'].description, pattern=QUERY_PARAMETERS['annotations']['response_fields'].metadata[0].pattern)] = QUERY_PARAMETERS['defaults'].response_fields
class-attribute
instance-attribute
¶
response_format: Annotated[str | None, Field(description=QUERY_PARAMETERS['annotations']['response_format'].description)] = QUERY_PARAMETERS['defaults'].response_format
class-attribute
instance-attribute
¶
sort: Annotated[str | None, Field(description=QUERY_PARAMETERS['annotations']['sort'].description, pattern=QUERY_PARAMETERS['annotations']['sort'].metadata[0].pattern)] = QUERY_PARAMETERS['defaults'].sort
class-attribute
instance-attribute
¶
QueryCreate
¶
Bases: EntryResourceCreate
, QueryResourceAttributes
Model for creating new Query resources in the MongoDB
Source code in optimade_gateway/models/queries.py
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
|
endpoint: Annotated[EndpointEntryType | None, Field(title=QueryResourceAttributes.model_fields['endpoint'].title, description=QueryResourceAttributes.model_fields['endpoint'].description, json_schema_extra=QueryResourceAttributes.model_fields['endpoint'].json_schema_extra)] = None
class-attribute
instance-attribute
¶
state: Annotated[QueryState | None, Field(title=QueryResourceAttributes.model_fields['state'].title, description=QueryResourceAttributes.model_fields['state'].description, json_schema_extra=QueryResourceAttributes.model_fields['state'].json_schema_extra)] = None
class-attribute
instance-attribute
¶
sort_not_supported(value)
classmethod
¶
Warn and reset value if sort
is supplied.
Source code in optimade_gateway/models/queries.py
470 471 472 473 474 475 476 477 478 479 |
|
QueryParameters
¶
Bases: TypedDict
Type definition for QUERY_PARAMETERS
.
Source code in optimade_gateway/models/queries.py
41 42 43 44 45 |
|
QueryResource
¶
Bases: EntryResource
OPTIMADE query resource for a gateway
Source code in optimade_gateway/models/queries.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
|
attributes: QueryResourceAttributes
instance-attribute
¶
type: Annotated[Literal['queries'], Field(description='The name of the type of an entry.')] = 'queries'
class-attribute
instance-attribute
¶
response_as_optimade(url=None)
async
¶
Return attributes.response
as a valid OPTIMADE entry listing response.
Note, this method disregards the state of the query and will simply return the query results as they currently are (if there are any at all).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
None | ParseResult | SplitResult | URL | str
|
Optionally, update the |
None
|
Returns:
Type | Description |
---|---|
EntryResponseMany | ErrorResponse
|
A valid OPTIMADE entry-listing response according to the |
EntryResponseMany | ErrorResponse
|
|
EntryResponseMany | ErrorResponse
|
or an error response, if errors were returned or occurred during the query. |
Source code in optimade_gateway/models/queries.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
|
QueryResourceAttributes
¶
Bases: EntryResourceAttributes
Attributes for an OPTIMADE gateway query.
Source code in optimade_gateway/models/queries.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 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 |
|
endpoint: Annotated[EndpointEntryType, Field(description="The entry endpoint queried, e.g., 'structures'.", title='Endpoint', json_schema_extra={'type': 'enum'})] = EndpointEntryType.STRUCTURES
class-attribute
instance-attribute
¶
gateway_id: Annotated[str, Field(description='The OPTIMADE gateway ID for this query.')]
instance-attribute
¶
query_parameters: Annotated[OptimadeQueryParameters, Field(description='OPTIMADE query parameters for entry listing endpoints used for this query.', json_schema_extra={'type': 'object'})]
instance-attribute
¶
response: Annotated[GatewayQueryResponse | None, Field(description='Response from gateway query.')] = None
class-attribute
instance-attribute
¶
state: Annotated[QueryState, Field(description='Current state of Gateway Query.', title='State', json_schema_extra={'type': 'enum'})] = QueryState.CREATED
class-attribute
instance-attribute
¶
only_allow_structures(value)
classmethod
¶
Temporarily only allow queries to "structures" endpoints.
Source code in optimade_gateway/models/queries.py
318 319 320 321 322 323 324 325 326 327 |
|
QueryState
¶
Bases: Enum
Enumeration of possible states for a Gateway Query.
The states are enumerated here in the expected evolvement.
Source code in optimade_gateway/models/queries.py
198 199 200 201 202 203 204 205 206 207 |
|