httk.serve.optimade.backend.adapter

Adapt store/searcher implementations to the OPTIMADE backend contract.

Attributes

Classes

EntrySource

Describe one queryable source behind an OPTIMADE entry endpoint.

BackendAdapter

Bind a store to the OPTIMADE entry endpoints it serves.

Module Contents

type httk.serve.optimade.backend.adapter.FieldExtractor = Callable[[Any], Any][source]
class httk.serve.optimade.backend.adapter.EntrySource[source]

Describe one queryable source behind an OPTIMADE entry endpoint.

target is what gets passed to searcher.variable(); fields maps OPTIMADE response-field names to extractors applied to matched row objects. relationships, when set, is an extractor mapping a matched row to a dictionary keyed by related entry type, each value a list of {'id': str, 'description': str?, 'role': str?} dictionaries. sort_keys maps response-field names to the backend field names to sort on. property_metadata maps response-field names to extractors returning the per-property metadata dictionary for a matched row (or None when there is no metadata for that row).

Parameters:
  • target – Store-specific target passed to searcher.variable.

  • fields – Response-field extractors applied to matched rows.

  • sort_keys – Response-field to backend-sort-field mappings.

  • relationships – Optional extractor for related-resource data.

  • property_metadata – Optional per-property metadata extractors.

target: Any[source]
fields: collections.abc.Mapping[str, FieldExtractor][source]
sort_keys: collections.abc.Mapping[str, str][source]
relationships: FieldExtractor | None = None[source]
property_metadata: collections.abc.Mapping[str, FieldExtractor][source]
class httk.serve.optimade.backend.adapter.BackendAdapter[source]

Bind a store to the OPTIMADE entry endpoints it serves.

sources maps entry endpoint names (e.g. 'structures') to the sources queried for that endpoint; an endpoint with several sources (e.g. several calculation result types) is queried across all of them.

schema is required: it declares the served entry types and properties. field_handlers maps each entry type to its filter-handler table. When omitted (left empty) it is derived from schema via simple_property_handlers(), using an identity property-key map (each property is filtered against a backend field of the same name); a backend whose field names differ, or that wants finer control, supplies its own tables instead.

Parameters:
  • store – Store implementing the neutral query protocol.

  • sources – Queryable sources keyed by entry endpoint.

  • schema – Required schema describing served entries and properties.

  • field_handlers – Optional filter handlers keyed by entry endpoint.

store: httk.store.query.Store[source]
sources: collections.abc.Mapping[str, collections.abc.Sequence[EntrySource]][source]
schema: httk.serve.optimade.schema.served.ServedSchema[source]
field_handlers: collections.abc.Mapping[str, httk.store.query.optimade_filters.HandlerTable][source]
query_function()[source]

Return the callback that executes queries through this adapter.

Returns:

Query callback consumed by the OPTIMADE request engine.

Return type:

httk.serve.optimade.model.results.QueryFunction