httk.optimade.backend.memory_store

A generic in-memory store implementing the httk store/searcher protocols.

Rows are plain dicts keyed by backend record keys, and search expressions evaluate as predicates over those rows. It is the reference Store implementation: it backs the example demo server and is what adapter_from_providers() loads an EntryProvider’s records into.

Set operations evaluate exactly here — has_any/has_only are plain set predicates over the row’s list value, and ~ negates them directly. The SQL backend needs an aggregate rendering and a second (HAVING) evaluation position to say the same thing, but that is entirely its own business: the neutral protocol only ever hands a store one expression per searcher.add call.

String matching is literal here too (contains/startswith/endswith are plain str operations), which is exactly what the neutral protocol promises — no pattern language is involved at any point.

Iteration yields SearchResult values, one entry in values per MemorySearcher.output() call: a variable output yields the whole row dict, a field output the row’s value for that field.

Attributes

Classes

MemoryExpression

MemoryField

MemoryVariable

A query variable over one table of rows; attribute access yields fields.

MemorySearcher

InMemoryStore

A store over dict rows: InMemoryStore({'structures': [ {...}, ... ]}).

Module Contents

httk.optimade.backend.memory_store.Row[source]
httk.optimade.backend.memory_store.Predicate[source]
class httk.optimade.backend.memory_store.MemoryExpression(predicate: Predicate)[source]
predicate[source]
class httk.optimade.backend.memory_store.MemoryField(name: str)[source]
name[source]
startswith(other: str) MemoryExpression[source]
endswith(other: str) MemoryExpression[source]
contains(other: str) MemoryExpression[source]
has_any(*values: Any) MemoryExpression[source]
has_only(*values: Any) MemoryExpression[source]
class httk.optimade.backend.memory_store.MemoryVariable(target: str)[source]

A query variable over one table of rows; attribute access yields fields.

always_true/always_false are real methods, declared before the catch-all __getattr__ so they win over it — they are reserved names that never resolve to a row key.

target[source]
always_true() MemoryExpression[source]
always_false() MemoryExpression[source]
class httk.optimade.backend.memory_store.MemorySearcher(tables: dict[str, list[Row]])[source]
offset = 0[source]
variable(target: Any) MemoryVariable[source]
output(variable: MemoryVariable | MemoryField, name: str) None[source]

Append an output: a variable (yields the whole row) or a field (its value).

add(expression: MemoryExpression) None[source]
add_sort(field: MemoryField, descending: bool) None[source]
count() int[source]
set_limit(limit: int) None[source]
add_offset(offset: int) None[source]
class httk.optimade.backend.memory_store.InMemoryStore(tables: dict[str, list[Row]])[source]

A store over dict rows: InMemoryStore({'structures': [ {...}, ... ]}).

tables[source]
searcher() MemorySearcher[source]