httk.serve.optimade.endpoints

Public OPTIMADE endpoint response generators.

Submodules

Functions

generate_entry_endpoint_reply(request, config, data[, ...])

Build a JSON:API collection response for an entry endpoint.

generate_single_entry_endpoint_reply(request, config, data)

Build a JSON:API single-resource response for an entry identifier.

format_optimade_error(ex, request, config[, version])

Format an exception as an OPTIMADE error response.

generate_base_endpoint_reply(request, config)

Build the HTML response for the unversioned API base endpoint.

generate_entry_info_endpoint_reply(request, config, ...)

Build the /info/{entry} response for one served entry type.

generate_info_endpoint_reply(request, config, schema)

Build the service /info response.

generate_links_endpoint_reply(request, config)

Build the provider-links response.

generate_versions_endpoint_reply(request, config)

Build the preference-ordered CSV of supported API major versions.

generate_meta(*, representation, api_version, config)

Build the OPTIMADE response metadata object.

Package Contents

httk.serve.optimade.endpoints.generate_entry_endpoint_reply(request, config, data, data_available=None, related_resolver=None)[source]

Build a JSON:API collection response for an entry endpoint.

Parameters:
Returns:

JSON:API collection document.

Return type:

dict[str, Any]

httk.serve.optimade.endpoints.generate_single_entry_endpoint_reply(request, config, data, data_available=None, related_resolver=None)[source]

Build a JSON:API single-resource response for an entry identifier.

Parameters:
Returns:

JSON:API single-resource document.

Raises:

httk.serve.optimade.model.errors.OptimadeError – If the query yields multiple rows or another page.

Return type:

dict[str, Any]

httk.serve.optimade.endpoints.format_optimade_error(ex, request, config, version=optimade_default_version)[source]

Format an exception as an OPTIMADE error response.

Parameters:
Returns:

JSON:API error response.

Return type:

httk.serve.optimade.model.request.EndpointResponse

httk.serve.optimade.endpoints.generate_base_endpoint_reply(request, config)[source]

Build the HTML response for the unversioned API base endpoint.

Parameters:
Returns:

HTML response body.

Return type:

str

httk.serve.optimade.endpoints.generate_entry_info_endpoint_reply(request, config, entry, schema)[source]

Build the /info/{entry} response for one served entry type.

Parameters:
Returns:

JSON:API entry-info document.

Return type:

dict[str, Any]

httk.serve.optimade.endpoints.generate_info_endpoint_reply(request, config, schema)[source]

Build the service /info response.

Parameters:
Returns:

JSON:API service-info document.

Return type:

dict[str, Any]

Build the provider-links response.

Parameters:
Returns:

JSON:API links document.

Return type:

dict[str, Any]

httk.serve.optimade.endpoints.generate_versions_endpoint_reply(request, config)[source]

Build the preference-ordered CSV of supported API major versions.

Parameters:
Returns:

Restricted /versions CSV body.

Return type:

str

httk.serve.optimade.endpoints.generate_meta(*, representation, api_version, config, data_returned=None, more_data_available=False, data_available=None, warnings=None, last_id=None)[source]

Build the OPTIMADE response metadata object.

Parameters:
  • representation (str) – Request representation recorded in metadata.

  • api_version (str) – OPTIMADE version used for the response.

  • config (httk.serve.optimade.model.config.OptimadeConfig) – Service metadata configuration.

  • data_returned (int | None) – Total data objects for the current filter query, independent of pagination.

  • more_data_available (bool) – Whether another page is available.

  • data_available (int | None) – Total data objects available in the database for the endpoint (unfiltered).

  • warnings (list[dict[str, Any]] | None) – Warnings already associated with the request.

  • last_id (str | None) – Identifier of the final returned entry.

Returns:

OPTIMADE metadata mapping.

Return type:

dict[str, Any]