httk.data.entry_providers¶
In-memory EntryProvider implementations for the standard entry types.
These providers map {id: record} mappings of the stdlib-only record models
defined in httk-core (Reference, File,
Calculation) onto the neutral httk-core entry-provider
contract, so a serving module (such as httk-optimade) can expose them as
OPTIMADE references/files/calculations endpoints without either side
depending on the other. Each provider describes its entry type with the vendored
OPTIMADE standard definition loaded from httk-core via
standard_entry_type().
The record models live in httk-core (contracts and models); these providers
live in httk-data (the capability layer built on those models), together with
property-definition validation. The database storage layer in
httk.data.db complements them with a database-backed provider
(StoreEntryProvider) serving stored
dataclasses the same way.
Classes¶
Serves OPTIMADE |
|
Serves OPTIMADE |
|
Serves OPTIMADE |
Module Contents¶
- class httk.data.entry_providers.ReferenceEntryProvider(entries: collections.abc.Mapping[str, httk.core.Reference | collections.abc.Mapping[str, Any]], *, relationships: collections.abc.Mapping[str, collections.abc.Iterable[httk.core.RelatedEntry]] | None = None)[source]¶
Bases:
httk.core.EntryProviderServes OPTIMADE
referencesfrom a mapping of id toReference.relationshipsoptionally maps a reference id to its related entries (RelatedEntryvalues, served flat per id).- entry_types() collections.abc.Mapping[str, httk.core.EntryTypeDefinition][source]¶
Return the served entry types keyed by name.
Each value is an
EntryTypeDefinitiondescribing the entry type and its properties. The subset a provider actually serves is named byproperty_keys(); a definition may describe more properties than are served.
- property_keys(entry_type: str) collections.abc.Mapping[str, str][source]¶
Return the served-property-name to record-key map for
entry_type.The mapping MUST include entries for at least
idandtype. Every key names a property described byentry_types(); every value names the key under which that property’s value is found in a record fromrecords().
- records(entry_type: str) collections.abc.Iterable[collections.abc.Mapping[str, Any]][source]¶
Yield the records for
entry_typeas plain JSON-able mappings.Each record is a mapping keyed by the record keys named in
property_keys(); values are JSON-able (strings, numbers, booleans,None, or nested lists/dicts of the same).
- relationships(entry_type: str) collections.abc.Mapping[str, tuple[httk.core.RelatedEntry, Ellipsis]][source]¶
Return the related entries for each record of
entry_type.The result maps an entry id to a flat tuple of
RelatedEntryvalues, e.g.{"struct-1": (RelatedEntry("references", "ref-1"), RelatedEntry("references", "ref-2", description="Cites the method"))}. Grouping the related entries by related entry type is the serving layer’s concern (JSON:API groups them at render time). This is the neutral source of an OPTIMADE relationships block: a consumer turns each related entry into a resource identifier under its entry type (carrying thedescription/rolemetadata when present), and aninclude=<type>request then embeds those related resources. The default implementation returns an empty mapping (no relationships); a provider overrides it to declare them. Ids referring to records this provider (or a sibling provider serving the related type) does not supply are simply not resolvable by the consumer.
- class httk.data.entry_providers.FileEntryProvider(entries: collections.abc.Mapping[str, httk.core.File | collections.abc.Mapping[str, Any]], *, relationships: collections.abc.Mapping[str, collections.abc.Iterable[httk.core.RelatedEntry]] | None = None)[source]¶
Bases:
httk.core.EntryProviderServes OPTIMADE
filesfrom a mapping of id toFile.relationshipsoptionally maps a file id to its related entries (RelatedEntryvalues, served flat per id) — e.g. the calculations a file isinput/outputof.- entry_types() collections.abc.Mapping[str, httk.core.EntryTypeDefinition][source]¶
Return the served entry types keyed by name.
Each value is an
EntryTypeDefinitiondescribing the entry type and its properties. The subset a provider actually serves is named byproperty_keys(); a definition may describe more properties than are served.
- property_keys(entry_type: str) collections.abc.Mapping[str, str][source]¶
Return the served-property-name to record-key map for
entry_type.The mapping MUST include entries for at least
idandtype. Every key names a property described byentry_types(); every value names the key under which that property’s value is found in a record fromrecords().
- records(entry_type: str) collections.abc.Iterable[collections.abc.Mapping[str, Any]][source]¶
Yield the records for
entry_typeas plain JSON-able mappings.Each record is a mapping keyed by the record keys named in
property_keys(); values are JSON-able (strings, numbers, booleans,None, or nested lists/dicts of the same).
- relationships(entry_type: str) collections.abc.Mapping[str, tuple[httk.core.RelatedEntry, Ellipsis]][source]¶
Return the related entries for each record of
entry_type.The result maps an entry id to a flat tuple of
RelatedEntryvalues, e.g.{"struct-1": (RelatedEntry("references", "ref-1"), RelatedEntry("references", "ref-2", description="Cites the method"))}. Grouping the related entries by related entry type is the serving layer’s concern (JSON:API groups them at render time). This is the neutral source of an OPTIMADE relationships block: a consumer turns each related entry into a resource identifier under its entry type (carrying thedescription/rolemetadata when present), and aninclude=<type>request then embeds those related resources. The default implementation returns an empty mapping (no relationships); a provider overrides it to declare them. Ids referring to records this provider (or a sibling provider serving the related type) does not supply are simply not resolvable by the consumer.
- class httk.data.entry_providers.CalculationEntryProvider(entries: collections.abc.Mapping[str, httk.core.Calculation | collections.abc.Mapping[str, Any]], *, relationships: collections.abc.Mapping[str, collections.abc.Iterable[httk.core.RelatedEntry]] | None = None)[source]¶
Bases:
httk.core.EntryProviderServes OPTIMADE
calculationsfrom a mapping of id toCalculation.relationshipsoptionally maps a calculation id to its related entries (RelatedEntryvalues, served flat per id) — e.g. itsinput/outputfiles, expressed via therolemetadata.- entry_types() collections.abc.Mapping[str, httk.core.EntryTypeDefinition][source]¶
Return the served entry types keyed by name.
Each value is an
EntryTypeDefinitiondescribing the entry type and its properties. The subset a provider actually serves is named byproperty_keys(); a definition may describe more properties than are served.
- property_keys(entry_type: str) collections.abc.Mapping[str, str][source]¶
Return the served-property-name to record-key map for
entry_type.The mapping MUST include entries for at least
idandtype. Every key names a property described byentry_types(); every value names the key under which that property’s value is found in a record fromrecords().
- records(entry_type: str) collections.abc.Iterable[collections.abc.Mapping[str, Any]][source]¶
Yield the records for
entry_typeas plain JSON-able mappings.Each record is a mapping keyed by the record keys named in
property_keys(); values are JSON-able (strings, numbers, booleans,None, or nested lists/dicts of the same).
- relationships(entry_type: str) collections.abc.Mapping[str, tuple[httk.core.RelatedEntry, Ellipsis]][source]¶
Return the related entries for each record of
entry_type.The result maps an entry id to a flat tuple of
RelatedEntryvalues, e.g.{"struct-1": (RelatedEntry("references", "ref-1"), RelatedEntry("references", "ref-2", description="Cites the method"))}. Grouping the related entries by related entry type is the serving layer’s concern (JSON:API groups them at render time). This is the neutral source of an OPTIMADE relationships block: a consumer turns each related entry into a resource identifier under its entry type (carrying thedescription/rolemetadata when present), and aninclude=<type>request then embeds those related resources. The default implementation returns an empty mapping (no relationships); a provider overrides it to declare them. Ids referring to records this provider (or a sibling provider serving the related type) does not supply are simply not resolvable by the consumer.