httk.serve.optimade¶
Submodules¶
Attributes¶
Exceptions¶
Base class for safe, client-side OPTIMADE failures. |
|
An |
|
A non-success response supplied a parseable OPTIMADE |
|
A remote endpoint returned a non-success HTTP status. |
|
The HTTP client could not complete a request. |
|
An OPTIMADE base URL could not be negotiated to a supported API version. |
|
Common base class for all non-exit exceptions. |
|
Common base class for all non-exit exceptions. |
|
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¶
Binds a store to the OPTIMADE entry endpoints it serves. |
|
One queryable source (table/type) behind an OPTIMADE entry endpoint. |
|
A store over dict rows: |
|
A synchronous read-only OPTIMADE service connection with eager discovery. |
|
One immutable remote entry endpoint discovered from |
|
A response produced by an endpoint, to be serialized by the web layer. |
|
Configuration of a served OPTIMADE database. |
|
An incoming OPTIMADE request, as handed over by the web layer. |
|
Validated URL query parameters of an OPTIMADE request. |
|
The result of validating a |
|
One named scalar projection from a lazy remote result set. |
|
A frozen, lazy and re-iterable remote OPTIMADE result plan. |
|
One portable single-root OPTIMADE query under construction. |
Functions¶
|
Create an ASGI application serving an OPTIMADE API for the given backend. |
|
Serve an OPTIMADE API for the given backend with a development web server. |
Build a |
|
|
Return the registered entry-provider factories keyed by their registered name. |
|
Process an OPTIMADE query. |
|
Precompute the number of available entries per entry endpoint. |
Package Contents¶
- httk.serve.optimade.create_asgi_app(adapter: httk.serve.optimade.backend.adapter.BackendAdapter, config: httk.serve.optimade.model.config.OptimadeConfig | None = None, *, baseurl: str | None = None, debug: bool = False) starlette.applications.Starlette[source]¶
Create an ASGI application serving an OPTIMADE API for the given backend.
- httk.serve.optimade.serve(adapter: httk.serve.optimade.backend.adapter.BackendAdapter, config: httk.serve.optimade.model.config.OptimadeConfig | None = None, *, host: str = '127.0.0.1', port: int = 8080, baseurl: str | None = None, debug: bool = False) None[source]¶
Serve an OPTIMADE API for the given backend with a development web server.
- class httk.serve.optimade.BackendAdapter[source]¶
Binds a store to the OPTIMADE entry endpoints it serves.
sourcesmaps entry endpoint names (e.g.'structures') to the sources queried for that endpoint; an endpoint with several sources (e.g. several calculation result types) is queried across all of them.schemais required: it declares the served entry types and properties.field_handlersmaps each entry type to its filter-handler table. When omitted (left empty) it is derived fromschemaviasimple_property_handlers(), using an identity property-key map (each property is filtered against a backend field of the same name); a backend whose field names differ, or that wants finer control, supplies its own tables instead.- store: httk.data.query.Store¶
- field_handlers: collections.abc.Mapping[str, httk.data.optimade_query.HandlerTable]¶
- query_function() httk.serve.optimade.model.results.QueryFunction[source]¶
- class httk.serve.optimade.EntrySource[source]¶
One queryable source (table/type) behind an OPTIMADE entry endpoint.
targetis what gets passed tosearcher.variable();fieldsmaps OPTIMADE response-field names to extractors applied to matched row objects.relationships, when set, is an extractor mapping a matched row to a dictionary keyed by related entry type, each value a list of{'id': str, 'description': str?, 'role': str?}dictionaries.sort_keysmaps response-field names to the backend field names to sort on.property_metadatamaps response-field names to extractors returning the per-property metadata dictionary for a matched row (orNonewhen there is no metadata for that row).- target: Any¶
- fields: collections.abc.Mapping[str, FieldExtractor]¶
- sort_keys: collections.abc.Mapping[str, str]¶
- relationships: FieldExtractor | None = None¶
- property_metadata: collections.abc.Mapping[str, FieldExtractor]¶
- class httk.serve.optimade.InMemoryStore(tables: dict[str, list[Row]])[source]¶
A store over dict rows:
InMemoryStore({'structures': [ {...}, ... ]}).- tables¶
- searcher() MemorySearcher[source]¶
- httk.serve.optimade.adapter_from_providers(providers: collections.abc.Iterable[httk.core.EntryProvider], **options: Any) httk.serve.optimade.backend.adapter.BackendAdapter[source]¶
Build a
BackendAdapterserving the given entry providers.Every provider’s
entry_types()become served entry types (described by theirEntryTypeDefinition), itsproperty_keys()name the served subset and drive both the filter handlers (viasimple_property_handlers()) and the response-field extractors, and itsrecords()are loaded into anInMemoryStore. Every served property MUST be described by the entry type’s definition (a custom property must therefore live in anextended()definition); aValueErrornames any offender. All served properties beyondid/typeare marked default-response. Extra keywordoptions(e.g.sortable,recognized_prefixes) are forwarded tobuild_served_schema(); every served property is sortable-capable, since the provider’s property-key map is passed through as the source’ssort_keys.Declared relationships (
relationships()) are fully auto-wired for serving and filtering: for each entry type with declared relationships, a synthetic__rel_<related_type>id-list field is materialized on EVERY row of that entry type (an empty list when the row has no related entries of that type, so inverse set semantics are well-defined), and a'<related_type>.id'entry built withrelationship_id_handler()is merged into the entry type’s derived filter-handler table (never overwriting an entry already present, mirroring howBackendAdapterrespects explicitly supplied handler tables).<related_type>.id HAS ...filters — and, through the related-property resolver oftranslate_filter(), depth-1 relationship-property filters such asreferences.doi CONTAINS "10.1"— therefore work without any hand-wiring.
- httk.serve.optimade.providers_from_registry() dict[str, collections.abc.Callable[Ellipsis, httk.core.EntryProvider]][source]¶
Return the registered entry-provider factories keyed by their registered name.
Resolves each factory registered via
httk.core.register_entry_provider()(throughhttk.registry.*self-registration) into a callable. Providers need data, so applications instantiate them:providers_from_registry()["atomistic-structures"](data).
- exception httk.serve.optimade.OptimadeClientError[source]¶
Bases:
RuntimeErrorBase class for safe, client-side OPTIMADE failures.
- exception httk.serve.optimade.OptimadeDiscoveryError(source_url: str, detail: str)[source]¶
Bases:
OptimadeClientErrorAn
/infodocument was malformed or inconsistent for discovery.- source_url¶
- detail¶
- exception httk.serve.optimade.OptimadeErrorDocumentError(source_url: str, status_code: int, detail: str | None = None)[source]¶
Bases:
OptimadeHTTPErrorA non-success response supplied a parseable OPTIMADE
errorsdocument.
- exception httk.serve.optimade.OptimadeHTTPError(source_url: str, status_code: int, detail: str | None = None)[source]¶
Bases:
OptimadeClientErrorA remote endpoint returned a non-success HTTP status.
- source_url¶
- status_code¶
- detail = None¶
- class httk.serve.optimade.OptimadeStore(base_url: str, *, client: object | None = None, page_limit: int = 100, max_pages: int = 10000, allow_cross_origin_pagination: bool = False, response_fields: object | None = None)[source]¶
A synchronous read-only OPTIMADE service connection with eager discovery.
- requested_base_url¶
- base_url¶
- page_limit = 100¶
- max_pages = 10000¶
- allow_cross_origin_pagination = False¶
- response_fields = None¶
- property entry_types: tuple[RemoteEntryType, Ellipsis]¶
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: str) RemoteEntryType[source]¶
Return one discovered endpoint by its transport name.
- searcher(*, response_fields: object = ...) httk.serve.optimade.remote_query.RemoteSearcher[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.
- exception httk.serve.optimade.OptimadeTransportError(source_url: str, detail: str)[source]¶
Bases:
OptimadeClientErrorThe HTTP client could not complete a request.
- source_url¶
- detail¶
- exception httk.serve.optimade.OptimadeVersionNegotiationError(source_url: str, detail: str)[source]¶
Bases:
OptimadeClientErrorAn OPTIMADE base URL could not be negotiated to a supported API version.
- source_url¶
- detail¶
- class httk.serve.optimade.RemoteEntryType[source]¶
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.- property_iris: collections.abc.Mapping[str, str]¶
- property_names: collections.abc.Mapping[str, str]¶
- binding: httk.core.OptimadeEntryBinding | None¶
- httk.serve.optimade.process(request: httk.serve.optimade.model.request.RawRequest, query_function: httk.serve.optimade.model.results.QueryFunction, version: str, config: httk.serve.optimade.model.config.OptimadeConfig, schema: httk.serve.optimade.schema.served.ServedSchema, *, debug: bool = False) httk.serve.optimade.model.request.EndpointResponse[source]¶
Process an OPTIMADE query.
requestcarries the incoming request; onlybaseurlandrepresentationmust be set, missing information is derived fromrepresentation.query_functionis the callback used to execute entry queries against the backend.schemadescribes the served entry types and properties.
- httk.serve.optimade.process_init(config: httk.serve.optimade.model.config.OptimadeConfig, query_function: httk.serve.optimade.model.results.QueryFunction, schema: httk.serve.optimade.schema.served.ServedSchema, *, debug: bool = False) None[source]¶
Precompute the number of available entries per entry endpoint.
- class httk.serve.optimade.EndpointResponse[source]¶
A response produced by an endpoint, to be serialized by the web layer.
Either
json_response(a JSON:API document) orcontent(a raw body) is set.
- class httk.serve.optimade.OptimadeConfig[source]¶
Configuration of a served OPTIMADE database.
implementationextends/overrides the fields of themeta->implementationdictionary (e.g.issue_tracker,source_url,maintainer).database,schema_url, andrequest_delaypopulate the corresponding optionalmetafields (OPTIMADE v1.2+) when set.license,available_licenses, andavailable_licenses_for_entriespopulate the corresponding optional base-info attributes when set.data_availableis filled in byprocess_initwith the number of available entries per entry endpoint.
- exception httk.serve.optimade.OptimadeError(message: str, response_code: int, response_message: str, longmsg: str | None = None)[source]¶
Bases:
ExceptionCommon base class for all non-exit exceptions.
- response_code¶
- response_msg¶
- content¶
- class httk.serve.optimade.RawRequest[source]¶
An incoming OPTIMADE request, as handed over by the web layer.
Only
baseurlandrepresentationare mandatory; missing information is derived fromrepresentationduring validation.
- exception httk.serve.optimade.TranslatorError(message: str, response_code: int, response_message: str, longmsg: str | None = None)[source]¶
Bases:
OptimadeErrorCommon base class for all non-exit exceptions.
- class httk.serve.optimade.ValidatedParameters[source]¶
Validated URL query parameters of an OPTIMADE request.
- dimension_slices: dict[str, RequestedSlice]¶
- class httk.serve.optimade.ValidatedRequest[source]¶
The result of validating a
RawRequest.- query: ValidatedParameters¶
Bases:
OptimadeResponseError,httk.data.CountUnavailableErrorThe service omitted a valid filtered
meta.data_availablecount.
- exception httk.serve.optimade.OptimadePaginationError[source]¶
Bases:
OptimadeResponseErrorA remote continuation was unsafe, malformed, or non-terminating.
- exception httk.serve.optimade.OptimadeResponseError[source]¶
Bases:
httk.serve.optimade.client.OptimadeClientErrorA successful HTTP response was not a usable OPTIMADE entry document.
- class httk.serve.optimade.RemoteResultColumn(result: RemoteResultSet, index: int)[source]¶
One named scalar projection from a lazy remote result set.
- name¶
- class httk.serve.optimade.RemoteResultSet(searcher: RemoteSearcher, outputs: collections.abc.Mapping[str, object] | None = None)[source]¶
A frozen, lazy and re-iterable remote OPTIMADE result plan.
- names¶
- first() httk.data.ResultRow | None[source]¶
- column(name: str) RemoteResultColumn[source]¶
- abstractmethod cursor() collections.abc.Iterator[httk.data.ResultRow][source]¶
- class httk.serve.optimade.RemoteSearcher(store: httk.serve.optimade.client.OptimadeStore, *, response_fields: object = None)[source]¶
One portable single-root OPTIMADE query under construction.
- offset = 0¶
- results(**outputs: object) RemoteResultSet[source]¶