httk.store.optimade¶
Public remote OPTIMADE client and query APIs.
The synchronous, read-only OPTIMADE client OptimadeStore and its
portable RemoteSearcher / RemoteResultSet query layer for
accessing remote (federated) OPTIMADE services.
Submodules¶
Attributes¶
Exceptions¶
Base class for safe, client-side OPTIMADE failures. |
|
Report a malformed or inconsistent |
|
Report a non-success response with a parseable OPTIMADE error document. |
|
Report a non-success HTTP status from a remote endpoint. |
|
Report that the HTTP client could not complete a request. |
|
Report failure to negotiate a supported OPTIMADE API version. |
|
The client could not obtain an exact filtered result count. |
|
A remote continuation was unsafe, malformed, or non-terminating. |
|
A successful HTTP response was not a usable OPTIMADE entry document. |
Classes¶
Connect synchronously to a read-only OPTIMADE service and discover it eagerly. |
|
Describe one immutable remote entry endpoint discovered from |
|
One specification deviation the client tolerated for a service. |
|
Expose one named scalar projection from a lazy result set. |
|
Represent a frozen, lazy, and re-iterable remote result plan. |
|
Build one portable single-root OPTIMADE query. |
Package Contents¶
- httk.store.optimade.ALL_ADVERTISED¶
- exception httk.store.optimade.OptimadeClientError¶
Bases:
RuntimeErrorBase class for safe, client-side OPTIMADE failures.
- exception httk.store.optimade.OptimadeDiscoveryError(source_url, detail)¶
Bases:
OptimadeClientErrorReport a malformed or inconsistent
/infodiscovery document.- Parameters:
- source_url¶
- detail¶
- exception httk.store.optimade.OptimadeErrorDocumentError(source_url, status_code, detail=None)¶
Bases:
OptimadeHTTPErrorReport a non-success response with a parseable OPTIMADE error document.
- exception httk.store.optimade.OptimadeHTTPError(source_url, status_code, detail=None)¶
Bases:
OptimadeClientErrorReport a non-success HTTP status from a remote endpoint.
- Parameters:
- source_url¶
- status_code¶
- detail = None¶
- class httk.store.optimade.OptimadeStore(base_url, *, client=None, timeout=120.0, page_limit=50, max_pages=10000, allow_cross_origin_pagination=False, response_fields=None, count_by_pagination=False, infer_standard_definitions=True, tolerate_deviations=True)¶
Connect synchronously to a read-only OPTIMADE service and discover it eagerly.
Unversioned bases negotiate strictly through the preference-ordered
/versionsCSV. Query pagination validates complete pages before yielding, uses lazy one-root exact-literal requests, and bounds continuation links by page count and origin.- Parameters:
base_url (str) – Absolute HTTP(S) service base URL.
client (object | None) – Optional borrowed synchronous HTTP client; when given, its own timeout configuration applies and
timeoutis ignored.timeout (float | None) – Request timeout in seconds for the client this store creates when
clientis not given (default 120; public providers routinely take several seconds per filtered query).Nonedisables the timeout.page_limit (int) – Requested default remote page size; lowered automatically when a service rejects it with HTTP 403.
max_pages (int) – Maximum continuation pages followed by one query.
allow_cross_origin_pagination (bool) – Permit continuation links on another origin.
response_fields (object | None) – Default response-field selection for new searchers.
count_by_pagination (bool) – Count IDs across all pages when the service omits
meta.data_returned.infer_standard_definitions (bool) – Complete unprefixed standard property names on standard endpoints from the declared specification version (the info document’s
meta.api_version) when the service publishes no$id. This governs discovery, entry-type binding, and typed query fields; set False for strict definition-only auditing, where only declared$iddefinitions are recognized. It does not affect an entry backend constructed directly over a rawOptimadeResource, which always applies the standard-name rule.tolerate_deviations (bool) – Apply specification-anchored fallbacks for known service deviations and record them in
deviations; set False to fail strictly, for conformance auditing.
- Raises:
OptimadeVersionNegotiationError – If the service cannot select a supported version.
OptimadeDiscoveryError – If discovery documents are malformed.
- requested_base_url¶
- base_url¶
- page_limit = 50¶
- max_pages = 10000¶
- timeout = 120.0¶
- allow_cross_origin_pagination = False¶
- response_fields = None¶
- count_by_pagination = False¶
- infer_standard_definitions = True¶
- tolerate_deviations = True¶
- property deviations: tuple[ServiceDeviation, ...]¶
Specification deviations this client tolerated, in observation order.
- property entry_types: tuple[RemoteEntryType, ...]¶
Discovered entry endpoints in the service-advertised order.
- property entry_types_by_name: collections.abc.Mapping[str, RemoteEntryType]¶
An immutable transport-name lookup for
entry_types.
- entry_type(name)¶
Return one discovered endpoint by transport name.
- refresh()¶
Refresh discovery state after a fully successful rediscovery.
- Raises:
OptimadeClientError – If the store is closed or discovery fails.
- close()¶
Close an internally owned HTTP client; borrowed clients stay open.
- searcher(*, response_fields=..., as_of=None)¶
Create one synchronous, read-only remote search plan.
Passing
response_fieldsoverrides the store-level selection. An omitted value inherits it, while explicitNonerequests the service default.- Parameters:
- Returns:
New remote search plan.
- Raises:
OptimadeClientError – If the store is closed.
ValueError – If a historic cutoff is requested.
- Return type:
- slicer(target)¶
A pandas-style
[]indexing view over one discovered entry endpoint.targetis a discoveredRemoteEntryType, or its transport endpoint name resolved the same way asentry_type(). Each terminal indexing operation runs its own fresh search against a searcher created with this store’s defaultresponse_fieldspolicy. No sorting is offered here – usesearcher()directly for a sorted or relationship query.- Parameters:
target (RemoteEntryType | str) – A discovered endpoint descriptor, or its endpoint name.
- Returns:
A slicer over the endpoint’s records.
- Raises:
KeyError – If
targetis a name with no discovered endpoint.- Return type:
- exception httk.store.optimade.OptimadeTransportError(source_url, detail)¶
Bases:
OptimadeClientErrorReport that the HTTP client could not complete a request.
- Parameters:
- source_url¶
- detail¶
- exception httk.store.optimade.OptimadeVersionNegotiationError(source_url, detail)¶
Bases:
OptimadeClientErrorReport failure to negotiate a supported OPTIMADE API version.
- Parameters:
- source_url¶
- detail¶
- class httk.store.optimade.RemoteEntryType¶
Describe one immutable remote entry endpoint discovered from
/info.nameis solely the service’s transport endpoint name. Semantic recognition is intentionally represented bybindingand is derived exclusively from definition IRIs.- Parameters:
name – Transport endpoint name.
definition_id – Entry-definition IRI, when advertised.
schema – Lossless schema snapshot from discovery.
property_iris – Transport property names keyed by definition IRI.
property_names – Local property names keyed by definition IRI.
property_types – Property kinds keyed by transport name.
advertised_properties – Properties advertised by the service.
default_response_properties – Properties returned by default.
sortable_properties – Properties accepted by remote sorting.
binding – Recognized semantic binding, when available.
backend – Backend class associated with the binding.
binding_evidence – Why the binding was selected –
"declared"when alinks.describedbyIRI selected it,"property-ids"when an unambiguous set of declared property definition IRIs did,"standard-name"when the declared specification version’s standard namespace did, andNonewhen the endpoint stays unbound.inferred_properties – Sorted transport names whose definition IRI came from standard-name completion rather than a declared
$id.
- property_iris: collections.abc.Mapping[str, str]¶
- property_names: collections.abc.Mapping[str, str]¶
- binding: httk.core.register.OptimadeEntryBinding | None¶
- class httk.store.optimade.ServiceDeviation¶
One specification deviation the client tolerated for a service.
- Parameters:
kind – Deviation category –
"versions-endpoint","entry-info-identity", or"continuation-scheme".url – Redacted URL the deviation was observed at.
detail – One factual sentence describing the applied fallback.
Bases:
OptimadeResponseError,httk.store.query.protocols.CountUnavailableErrorThe client could not obtain an exact filtered result count.
- exception httk.store.optimade.OptimadePaginationError¶
Bases:
OptimadeResponseErrorA remote continuation was unsafe, malformed, or non-terminating.
- exception httk.store.optimade.OptimadeResponseError¶
Bases:
httk.store.optimade.client.OptimadeClientErrorA successful HTTP response was not a usable OPTIMADE entry document.
- class httk.store.optimade.RemoteResultColumn(result, index)¶
Expose one named scalar projection from a lazy result set.
- Parameters:
result (RemoteResultSet) – Result set owning the projection.
index (int) – Zero-based projection index.
- name¶
- class httk.store.optimade.RemoteResultSet(searcher, outputs=None)¶
Represent a frozen, lazy, and re-iterable remote result plan.
- Parameters:
searcher (RemoteSearcher) – Search plan to clone.
outputs (collections.abc.Mapping[str, object] | None) – Optional output names mapped to the searcher’s projections.
- names¶
- first()¶
Return the first result, if present.
- Returns:
First row or
None.- Return type:
- one()¶
Return the only result.
- Returns:
Sole result row.
- Raises:
httk.store.NoResultError – If no result exists.
httk.store.MultipleResultsError – If more than one result exists.
- Return type:
- scalars(name=None)¶
Iterate one named scalar output from each result.
- Parameters:
name (str | None) – Output name, or
Nonewhen exactly one exists.- Returns:
Iterator over scalar values.
- Raises:
KeyError – If the named output is unknown.
ValueError – If no name is given and multiple outputs exist.
- Return type:
- column(name)¶
Return a lazy column for a scalar output.
- Parameters:
name (str) – Scalar output name.
- Returns:
Lazy result column.
- Raises:
- Return type:
- abstractmethod cursor()¶
Reject unsupported cursor access.
- Returns:
Never; remote OPTIMADE cursors are unsupported.
- Raises:
NotImplementedError – Remote OPTIMADE cursors are unavailable.
- Return type:
collections.abc.Iterator[httk.store.query.protocols.ResultRow]
- class httk.store.optimade.RemoteSearcher(store, *, response_fields=None)¶
Build one portable single-root OPTIMADE query.
- Parameters:
store (httk.store.optimade.client.OptimadeStore) – Remote OPTIMADE store used for discovery and requests.
response_fields (object) – Optional field-selection policy for this search.
- offset = 0¶
- variable(target)¶
Bind the query to one discovered remote entry type.
- Parameters:
target (object) – Discovered entry descriptor or registered backend class.
- Returns:
Query variable exposing portable fields.
- Raises:
httk.store.query.protocols.UnsupportedQueryError – If the target is not recognized or a root variable is already bound.
- Return type:
_RemoteVariable
- add(expression)¶
Add a filter expression to the query.
- Parameters:
expression (object) – Expression created by this searcher.
- Raises:
ValueError – If no query variable is bound.
httk.store.UnsupportedQueryError – If the expression belongs elsewhere.
- add_sort(field, descending=False)¶
Append a sortable field to the remote query.
- Parameters:
- Raises:
httk.store.UnsupportedQueryError – If the field is not portable or sortable.
- set_limit(limit)¶
Set the query result limit.
- Parameters:
limit (int) – Nonnegative limit, or a negative value for no bound.
- add_offset(offset)¶
Advance the query offset.
- Parameters:
offset (int) – Nonnegative number of matching rows to skip.
- count()¶
Return the filtered remote count.
A valid optional
meta.data_returnedis the fast path. If it is absent ornull, counting raises unless the store enables ID pagination explicitly.- Returns:
Exact number of filtered remote results.
- Raises:
CountUnavailableError – If no valid count is reported and ID pagination is disabled.
- Return type:
- results(**outputs)¶
Freeze the query as a lazy, re-iterable result set.
- Parameters:
**outputs (object) – Optional output names mapped to this searcher’s projections.
- Returns:
Frozen remote result plan.
- Raises:
ValueError – If no outputs are declared.
- Return type:
- slicer(target)¶
A pandas-style
[]indexing view over one discovered entry endpoint.Each terminal indexing operation runs against a fresh searcher minted with this searcher’s
response_fieldspolicy, so slicer operations never share filter state. No sorting is offered here – usesearcher()andadd_sort()directly for a sorted or relationship query.- Parameters:
target (httk.store.optimade.client.RemoteEntryType) – The discovered remote entry endpoint to index.
- Returns:
A slicer over
target.- Return type: