query¶
Data models related to OPTIMADE queries.
QUERY_PARAMETERS
¶
Entry listing URL query parameters from the optimade
package
(EntryListingQueryParams
).
OPTIMADEQueryParameters (BaseModel)
¶
Common OPTIMADE entry listing endpoint query parameters.
Source code in oteapi_optimade/models/query.py
class OPTIMADEQueryParameters(BaseModel, validate_assignment=True):
"""Common OPTIMADE entry listing endpoint query parameters."""
filter: Annotated[
Optional[str],
Field(
description=QUERY_PARAMETERS["annotations"]["filter"].description,
),
] = QUERY_PARAMETERS["defaults"].filter
response_format: Annotated[
Optional[str],
Field(
description=QUERY_PARAMETERS["annotations"]["response_format"].description,
),
] = QUERY_PARAMETERS["defaults"].response_format
email_address: Annotated[
Optional[EmailStr],
Field(
description=QUERY_PARAMETERS["annotations"]["email_address"].description,
),
] = QUERY_PARAMETERS["defaults"].email_address
response_fields: Annotated[
Optional[str],
Field(
description=QUERY_PARAMETERS["annotations"]["response_fields"].description,
pattern=QUERY_PARAMETERS["annotations"]["response_fields"]
.metadata[0]
.pattern,
),
] = QUERY_PARAMETERS["defaults"].response_fields
sort: Annotated[
Optional[str],
Field(
description=QUERY_PARAMETERS["annotations"]["sort"].description,
pattern=QUERY_PARAMETERS["annotations"]["sort"].metadata[0].pattern,
),
] = QUERY_PARAMETERS["defaults"].sort
page_limit: Annotated[
Optional[int],
Field(
description=QUERY_PARAMETERS["annotations"]["page_limit"].description,
ge=QUERY_PARAMETERS["annotations"]["page_limit"].metadata[0].ge,
),
] = QUERY_PARAMETERS["defaults"].page_limit
page_offset: Annotated[
Optional[int],
Field(
description=QUERY_PARAMETERS["annotations"]["page_offset"].description,
ge=QUERY_PARAMETERS["annotations"]["page_offset"].metadata[0].ge,
),
] = QUERY_PARAMETERS["defaults"].page_offset
page_number: Annotated[
Optional[int],
Field(
description=QUERY_PARAMETERS["annotations"]["page_number"].description,
# ge=QUERY_PARAMETERS["annotations"]["page_number"].metadata[0].ge,
# This constraint is only 'RECOMMENDED' in the specification, so should not
# be included here or in the OpenAPI schema.
),
] = QUERY_PARAMETERS["defaults"].page_number
page_cursor: Annotated[
Optional[int],
Field(
description=QUERY_PARAMETERS["annotations"]["page_cursor"].description,
ge=QUERY_PARAMETERS["annotations"]["page_cursor"].metadata[0].ge,
),
] = QUERY_PARAMETERS["defaults"].page_cursor
page_above: Annotated[
Optional[int],
Field(
description=QUERY_PARAMETERS["annotations"]["page_above"].description,
),
] = QUERY_PARAMETERS["defaults"].page_above
page_below: Annotated[
Optional[int],
Field(
description=QUERY_PARAMETERS["annotations"]["page_below"].description,
),
] = QUERY_PARAMETERS["defaults"].page_below
include: Annotated[
Optional[str],
Field(
description=QUERY_PARAMETERS["annotations"]["include"].description,
),
] = QUERY_PARAMETERS["defaults"].include
# api_hint is not yet initialized in `EntryListingQueryParams`.
# These values are copied verbatim from `optimade==0.16.10`.
api_hint: Annotated[
Optional[str],
Field(
description=(
"If the client provides the parameter, the value SHOULD have the format "
"`vMAJOR` or `vMAJOR.MINOR`, where MAJOR is a major version and MINOR is a"
" minor version of the API. For example, if a client appends "
"`api_hint=v1.0` to the query string, the hint provided is for major "
"version 1 and minor version 0."
),
pattern=r"(v[0-9]+(\.[0-9]+)?)?",
),
] = ""
def generate_query_string(self) -> str:
"""Generate a valid URL query string based on the set fields."""
res = {}
for field, value in self.model_dump().items():
if value or field in self.model_fields_set:
res[field] = unquote(value) if isinstance(value, str) else value
return urlencode(res, quote_via=quote)
model_computed_fields
¶
model_config
¶
model_fields
¶
generate_query_string(self)
¶
Generate a valid URL query string based on the set fields.
Source code in oteapi_optimade/models/query.py
def generate_query_string(self) -> str:
"""Generate a valid URL query string based on the set fields."""
res = {}
for field, value in self.model_dump().items():
if value or field in self.model_fields_set:
res[field] = unquote(value) if isinstance(value, str) else value
return urlencode(res, quote_via=quote)