httk.optimade.backend.protocols¶
Typed protocols for the store/searcher contract the OPTIMADE backend uses.
The store/searcher protocols are defined in httk.data.query (httk-data
is where httk’s data stores live, and this backend programs against their
shared query contract); this module re-exports them for the backend’s use,
together with the OPTIMADE-specific query-callable types from the result
model.
Classes¶
A single query under construction, and its results once iterated. |
|
Base class for protocol classes. |
|
A queryable field of a search variable. |
|
One match: the declared output values, and the names they were declared under. |
|
A query variable bound to a target type; attribute access yields fields. |
|
Base class for protocol classes. |
|
The callback seam through which the request engine runs queries on a backend. |
|
The results of a query against a backend, as consumed by the entry endpoints. |
Module Contents¶
- class httk.optimade.backend.protocols.Searcher[source]¶
Bases:
ProtocolA single query under construction, and its results once iterated.
Iteration yields one
SearchResultper match, soitem[0][0]is the first declared output of the match (typically the matched row object). The expressions received byaddare always ones produced by this same backend’s search variables, so implementations may type them as their own expression class; a backend that needs a second (post-filter) evaluation position decides that from the expression itself, not from the caller.
- class httk.optimade.backend.protocols.SearchExpression[source]¶
Bases:
ProtocolBase class for protocol classes.
Protocol classes are defined as:
class Proto(Protocol): def meth(self) -> int: ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example:
class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:
class GenProto[T](Protocol): def meth(self) -> T: ...
- class httk.optimade.backend.protocols.SearchField[source]¶
Bases:
ProtocolA queryable field of a search variable.
In addition to the methods below, fields support the rich comparison operators (
==,!=,<,<=,>,>=), returningSearchExpression. The handlers invoke those viagetattr(field, '__eq__')(value)since the comparison dunders cannot be typed as expression-returning.The three string-matching methods take literal text: no wildcard or pattern syntax whatsoever crosses this contract, so
%and_(and any other metacharacter) match themselves. A backend is therefore free to implement them with SQLLIKEover an escaped pattern, with a regular expression, or with a full-text index — the choice is invisible here.- has_any(*values: Any) SearchExpression[source]¶
- has_only(*values: Any) SearchExpression[source]¶
- contains(text: str) SearchExpression[source]¶
Match values containing
textas a literal substring.
- startswith(prefix: str) SearchExpression[source]¶
Match values beginning with the literal
prefix.
- endswith(suffix: str) SearchExpression[source]¶
Match values ending with the literal
suffix.
- class httk.optimade.backend.protocols.SearchResult[source]¶
Bases:
NamedTupleOne match: the declared output values, and the names they were declared under.
valuesholds one entry perSearcher.output()call in declaration order; it is a tuple, sovalues, names = resultandresult[0][0]both work.
- class httk.optimade.backend.protocols.SearchVariable[source]¶
Bases:
ProtocolA query variable bound to a target type; attribute access yields fields.
always_true/always_falseare reserved names: they are real methods of the variable, never stored fields resolved through__getattr__. They exist so a translation layer can express a constant truth value without inventing a probe field. Afield == fieldprobe is NULL-unsound, since it yields NULL (not true) for a NULL field.- always_true() SearchExpression[source]¶
An expression that matches every row.
- always_false() SearchExpression[source]¶
An expression that matches no row.
- class httk.optimade.backend.protocols.Store[source]¶
Bases:
ProtocolBase class for protocol classes.
Protocol classes are defined as:
class Proto(Protocol): def meth(self) -> int: ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example:
class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:
class GenProto[T](Protocol): def meth(self) -> T: ...
- class httk.optimade.backend.protocols.QueryFunction[source]¶
Bases:
ProtocolThe callback seam through which the request engine runs queries on a backend.