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 service omitted a valid filtered |
|
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 |
|
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¶
- exception httk.store.optimade.OptimadeClientError[source]¶
Bases:
RuntimeErrorBase class for safe, client-side OPTIMADE failures.
- exception httk.store.optimade.OptimadeDiscoveryError(source_url, detail)[source]¶
Bases:
OptimadeClientErrorReport a malformed or inconsistent
/infodiscovery document.- Parameters:
- source_url¶
- detail¶
- exception httk.store.optimade.OptimadeErrorDocumentError(source_url, status_code, detail=None)[source]¶
Bases:
OptimadeHTTPErrorReport a non-success response with a parseable OPTIMADE error document.
- exception httk.store.optimade.OptimadeHTTPError(source_url, status_code, detail=None)[source]¶
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, page_limit=50, max_pages=10000, allow_cross_origin_pagination=False, response_fields=None)[source]¶
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.
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.
- 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¶
- allow_cross_origin_pagination = False¶
- response_fields = None¶
- 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)[source]¶
Return one discovered endpoint by transport name.
- refresh()[source]¶
Refresh discovery state after a fully successful rediscovery.
- Raises:
OptimadeClientError – If the store is closed or discovery fails.
- searcher(*, response_fields=..., as_of=None)[source]¶
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)[source]¶
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)[source]¶
Bases:
OptimadeClientErrorReport that the HTTP client could not complete a request.
- Parameters:
- source_url¶
- detail¶
- exception httk.store.optimade.OptimadeVersionNegotiationError(source_url, detail)[source]¶
Bases:
OptimadeClientErrorReport failure to negotiate a supported OPTIMADE API version.
- Parameters:
- source_url¶
- detail¶
- class httk.store.optimade.RemoteEntryType[source]¶
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.
- property_iris: collections.abc.Mapping[str, str]¶
- property_names: collections.abc.Mapping[str, str]¶
- binding: httk.core.register.OptimadeEntryBinding | None¶
Bases:
OptimadeResponseError,httk.store.query.protocols.CountUnavailableErrorThe service omitted a valid filtered
meta.data_returnedcount.
- exception httk.store.optimade.OptimadePaginationError[source]¶
Bases:
OptimadeResponseErrorA remote continuation was unsafe, malformed, or non-terminating.
- exception httk.store.optimade.OptimadeResponseError[source]¶
Bases:
httk.store.optimade.client.OptimadeClientErrorA successful HTTP response was not a usable OPTIMADE entry document.
- class httk.store.optimade.RemoteResultColumn(result, index)[source]¶
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)[source]¶
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¶
- one()[source]¶
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)[source]¶
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)[source]¶
Return a lazy column for a scalar output.
- Parameters:
name (str) – Scalar output name.
- Returns:
Lazy result column.
- Raises:
- Return type:
- abstractmethod cursor()[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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.
- output(variable, name)[source]¶
Declare a whole-record, scalar, or set-valued relationship output.
A relationship namespace (
variable.links.<name>) is a set-valued output: it yields a tuple of bound related records per row, resolved from the response’sincludedarray or one lazy fetch per missing identifier – the same resolution a returned record’s own.links.<name>performs. Served-entry-type relationship names are also added to the request’sinclude=parameter automatically.- Parameters:
- Raises:
ValueError – If the name is empty or duplicated.
httk.store.UnsupportedQueryError – If the output belongs elsewhere.
- add_sort(field, descending=False)[source]¶
Append a sortable field to the remote query.
- Parameters:
- Raises:
httk.store.UnsupportedQueryError – If the field is not portable or sortable.
- set_limit(limit)[source]¶
Set the query result limit.
- Parameters:
limit (int) – Nonnegative limit, or a negative value for no bound.
- add_offset(offset)[source]¶
Advance the query offset.
- Parameters:
offset (int) – Nonnegative number of matching rows to skip.
- count()[source]¶
Return the filtered remote count.
- Returns:
meta.data_returnedreported by the service.- Raises:
CountUnavailableError – If the service omits a valid count.
- Return type:
- results(**outputs)[source]¶
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)[source]¶
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: