httk.core.optimade.resources¶
Exact, immutable source documents received from an OPTIMADE service.
OptimadeDocument deliberately stores the original response text. Use
OptimadeDocument.create when a document may be persisted: it removes
credentials specifically from the top-level pagination links.next value
without parsing and reserializing the whole response, so semantic URL values,
JSON number spelling, and unrelated whitespace remain authoritative. Direct
dataclass construction is also available when the caller controls the values.
Attributes¶
Classes¶
Original OPTIMADE response text and the URL from which it was obtained. |
|
Describe the |
|
Represent one immutable resource in an OPTIMADE response envelope. |
Functions¶
|
Return url without userinfo, recognized sensitive query parameters, or its fragment. |
Sanitize only top-level pagination URLs, preserving source authority. |
|
Return an OPTIMADE entry type and its derived info URL, if url has that shape. |
|
Return whether url has the shape of an OPTIMADE single-entry URL. |
|
|
Fetch one OPTIMADE entry and its schema snapshot from url. |
|
Return the immutable, Decimal-preserving root of document lazily. |
Module Contents¶
- httk.core.optimade.resources.redact_optimade_url(url)[source]¶
Return url without userinfo, recognized sensitive query parameters, or its fragment.
Non-URL strings are returned unchanged except for fragment removal. Non-sensitive URL spelling is retained byte-for-byte; decoding is used only to recognize query keys. Fragments are not semantically load-bearing for OPTIMADE URLs or file fetches and are never retained in diagnostics.
- httk.core.optimade.resources.redact_optimade_document_text(text)[source]¶
Sanitize only top-level pagination URLs, preserving source authority.
A direct string
links.nextor its JSON:API link-objecthrefhas recognized URL credentials removed. Every other byte remains untouched: in particular URL-like object keys, resource attributes, relationships, extension values, whitespace, and number spelling are semantic source data. Malformed JSON is returned unchanged because its envelope path cannot be identified safely without guessing.
- class httk.core.optimade.resources.OptimadeDocument[source]¶
Original OPTIMADE response text and the URL from which it was obtained.
Direct construction performs no sanitization. Use
create()before storing an externally sourced document or URL.- Parameters:
text – Original response text, optionally sanitized by
create().source_url – URL from which the response was obtained.
- class httk.core.optimade.resources.OptimadeSchemaSnapshot[source]¶
Describe the
/info/<entry_type>document for a resource response.- Parameters:
entry_type – Entry type named by the schema endpoint.
info_document – Source-exact schema response document.
- info_document: OptimadeDocument[source]¶
- httk.core.optimade.resources.optimade_entry_url_info(url)[source]¶
Return an OPTIMADE entry type and its derived info URL, if url has that shape.
- httk.core.optimade.resources.is_optimade_entry_url(url)[source]¶
Return whether url has the shape of an OPTIMADE single-entry URL.
- httk.core.optimade.resources.optimade_resource_from_url(url, *, timeout=None)[source]¶
Fetch one OPTIMADE entry and its schema snapshot from url.
Redirects follow
urllibdefaults. Both requests use the datastream layer and honortimeout(or its configured default when it isNone).- Parameters:
- Returns:
Resource backed by the entry and its schema snapshot.
- Raises:
ValueError – If the URL or either response is not a valid OPTIMADE resource.
- Return type:
- type httk.core.optimade.resources.FrozenJson = None | bool | int | Decimal | str | tuple['FrozenJson', ...] | Mapping[str, 'FrozenJson'][source]¶
- httk.core.optimade.resources.optimade_document_root(document)[source]¶
Return the immutable, Decimal-preserving root of document lazily.
This is intentionally a small public seam for source-model consumers that need to interpret an OPTIMADE envelope or an
/infodocument without duplicating JSON parsing. The returned mapping is cached per equalOptimadeDocumentand must be treated as immutable.- Parameters:
document (OptimadeDocument) – Source document to parse lazily.
- Returns:
Cached immutable document root.
- Raises:
ValueError – If the document is invalid JSON or has a non-object root.
- Return type:
- class httk.core.optimade.resources.OptimadeResource[source]¶
Bases:
collections.abc.Mapping[str,FrozenJson]Represent one immutable resource in an OPTIMADE response envelope.
- Parameters:
document – Source-exact response document to decode lazily.
data_index – Index of the resource in the response
datamember.schema – Schema snapshot applicable to the response.
- document: OptimadeDocument[source]¶
- schema: OptimadeSchemaSnapshot[source]¶
- unwrap()[source]¶
Return the immutable resource object at this response’s data index.
- Returns:
Immutable resource mapping selected from the response.
- Raises:
TypeError – If
data_indexis not an integer.IndexError – If
data_indexis outside the response data.ValueError – If the response data is not an object or array of objects.
- Return type: