httk.core.optimade¶
OPTIMADE resources, typed entries, and filter parsing.
Submodules¶
Attributes¶
Exceptions¶
A resource lacks, nulls, or malforms a local record property. |
|
Common base class for all non-exit exceptions. |
|
Common base class for all non-exit exceptions. |
Classes¶
Present an |
|
Present an |
|
Bind an OPTIMADE resource to the standard calculations schema. |
|
Store one typed handle around an authoritative OPTIMADE resource. |
|
Present one typed resource backend as a lazy generated record. |
|
Bind an OPTIMADE resource to the standard files schema. |
|
Bind an OPTIMADE resource to the standard references schema. |
|
Present an |
|
Original OPTIMADE response text and the URL from which it was obtained. |
|
Represent one immutable resource in an OPTIMADE response envelope. |
|
Describe the |
Functions¶
|
Decode one value exactly from its local property definition. |
|
Parse an OPTIMADE filter into the public abstract syntax tree format. |
|
Parse an OPTIMADE filter and return its raw grammar parse tree. |
Return whether url has the shape of an OPTIMADE single-entry URL. |
|
|
Return the immutable, Decimal-preserving root of document lazily. |
Return an OPTIMADE entry type and its derived info URL, if url has that shape. |
|
|
Fetch one OPTIMADE entry and its schema snapshot from url. |
Sanitize only top-level pagination URLs, preserving source authority. |
|
|
Return url without userinfo, recognized sensitive query parameters, or its fragment. |
Package Contents¶
- class httk.core.optimade.CalculationView(backend)[source]¶
Bases:
OptimadeEntryViewPresent an
OptimadeCalculationas a lazy canonical view.- Parameters:
backend (OptimadeEntryBackend | OptimadeEntryView) – Calculation backend to present, or an existing compatible view.
- backend_class¶
- record_class¶
- class httk.core.optimade.FileView(backend)[source]¶
Bases:
OptimadeEntryViewPresent an
OptimadeFileas a lazy canonical view.- Parameters:
backend (OptimadeEntryBackend | OptimadeEntryView) – File backend to present, or an existing compatible view.
- backend_class¶
- record_class¶
- exception httk.core.optimade.IncompleteOptimadeResourceError[source]¶
Bases:
ValueErrorA resource lacks, nulls, or malforms a local record property.
- class httk.core.optimade.OptimadeCalculation[source]¶
Bases:
OptimadeEntryBackendBind an OPTIMADE resource to the standard calculations schema.
- Parameters:
resource – Source resource and its schema provenance.
- class httk.core.optimade.OptimadeEntryBackend[source]¶
Store one typed handle around an authoritative OPTIMADE resource.
- Parameters:
resource – Source resource and its schema provenance.
- property raw: collections.abc.Mapping[str, httk.core.optimade.resources.FrozenJson]¶
The immutable JSON API resource mapping, retaining source provenance.
- unwrap()[source]¶
Return the exact source resource, including document and schema provenance.
- Returns:
The source resource represented by this backend.
- Return type:
- property local_schema: httk.core.property_definitions.EntryTypeDefinition¶
Return the standard local schema for this backend.
- value_by_definition_id(definition_id, *, default=_MISSING)[source]¶
Return a raw value by exact semantic IRI, retaining missing vs. null.
Values are intentionally undecoded here. This lets record views name missing/null semantic properties accurately and gives callers access to exact raw JSON before selecting a representation.
- Parameters:
- Returns:
The raw property value, or
defaultwhen it is absent.- Raises:
ValueError – If the resource attributes or schema mapping is malformed.
- Return type:
- decode_value(definition, value)[source]¶
Decode value, applying an exact-IRI binding override when present.
- Parameters:
definition (httk.core.property_definitions.PropertyDefinition) – Local property definition for the value.
value (object) – Raw value to decode.
- Returns:
Decoded value from the matching generic or binding-specific decoder.
- Raises:
TypeError – If the value does not match the selected property decoder.
ValueError – If the property definition or value is invalid.
- Return type:
- property last_modified: datetime.datetime | None¶
Return the optional last-modified timestamp.
- class httk.core.optimade.OptimadeEntryView(backend)[source]¶
Present one typed resource backend as a lazy generated record.
- Parameters:
backend (OptimadeEntryBackend | OptimadeEntryView) – Typed backend to present, or an existing compatible view.
- backend_class: ClassVar[type[OptimadeEntryBackend]]¶
- record_class: ClassVar[type[httk.core.entry_types.Reference] | type[httk.core.entry_types.File] | type[httk.core.entry_types.Calculation]]¶
- property backend: OptimadeEntryBackend¶
Return the typed backend behind this view.
- property record: httk.core.entry_types.Reference | httk.core.entry_types.File | httk.core.entry_types.Calculation¶
Return the lazily materialized canonical record.
- class httk.core.optimade.OptimadeFile[source]¶
Bases:
OptimadeEntryBackendBind an OPTIMADE resource to the standard files schema.
- Parameters:
resource – Source resource and its schema provenance.
- class httk.core.optimade.OptimadeReference[source]¶
Bases:
OptimadeEntryBackendBind an OPTIMADE resource to the standard references schema.
- Parameters:
resource – Source resource and its schema provenance.
- class httk.core.optimade.ReferenceView(backend)[source]¶
Bases:
OptimadeEntryViewPresent an
OptimadeReferenceas a lazy canonical view.- Parameters:
backend (OptimadeEntryBackend | OptimadeEntryView) – Reference backend to present, or an existing compatible view.
- backend_class¶
- record_class¶
- httk.core.optimade.decode_optimade_value(definition, value)[source]¶
Decode one value exactly from its local property definition.
Binding-specific decoder callables use the stable signature
decoder(value, definition)and replace this generic decoder for their exact property-definition IRI. JSON floats are retained asDecimal; nested lists and dictionaries become tuples and immutable mappings.- Parameters:
definition (httk.core.property_definitions.PropertyDefinition) – Local property definition that describes the value.
value (object) – Raw value to decode.
- Returns:
Decoded value with nested containers made immutable.
- Raises:
TypeError – If the value does not match the declared property shape.
ValueError – If the property definition is unsupported or malformed.
- Return type:
- exception httk.core.optimade.ParserError[source]¶
Bases:
ExceptionCommon base class for all non-exit exceptions.
- exception httk.core.optimade.ParserSyntaxError(*args)[source]¶
Bases:
ParserErrorCommon base class for all non-exit exceptions.
- info¶
- line¶
- pos¶
- linestr¶
- httk.core.optimade.parse_optimade_filter(filter_string, verbosity=0)[source]¶
Parse an OPTIMADE filter into the public abstract syntax tree format.
- Parameters:
- Returns:
Nested tuple abstract syntax tree in
ojfformat.- Raises:
ParserError – If the filter cannot be parsed.
- Return type:
- httk.core.optimade.parse_optimade_filter_raw(filter_string, verbosity=0)[source]¶
Parse an OPTIMADE filter and return its raw grammar parse tree.
- Parameters:
- Returns:
Raw nested tuple parse tree before
ojfconversion.- Raises:
ParserError – If the filter cannot be parsed.
- Return type:
tuple[Any, Ellipsis]
- class httk.core.optimade.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.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¶
- schema: OptimadeSchemaSnapshot¶
- 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:
- class httk.core.optimade.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¶
- httk.core.optimade.is_optimade_entry_url(url)[source]¶
Return whether url has the shape of an OPTIMADE single-entry URL.
- httk.core.optimade.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:
- httk.core.optimade.optimade_entry_url_info(url)[source]¶
Return an OPTIMADE entry type and its derived info URL, if url has that shape.
- httk.core.optimade.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:
- httk.core.optimade.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.
- httk.core.optimade.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.