qhana_plugin_runner.api.util module

Module containing utilities for flask smorest APIs.

class qhana_plugin_runner.api.util.DataUrlValidator(*, relative: bool = False, absolute: bool = True, schemes: Sequence[str] | AbstractSet[str] | None = None, require_tld: bool = True, error: str | None = None)

Bases: URL

Extension of the URL validator that can handle file and data URLs

default_schemes = {'data', 'ftp', 'ftps', 'http', 'https'}
class qhana_plugin_runner.api.util.FileUrl(*, relative: bool = False, schemes: Sequence[str] | AbstractSet[str] | None = None, require_tld: bool = True, data_input_type: str | None = None, data_content_types: Sequence[str] | str | None = None, required: bool = False, allow_none: bool = False, **kwargs)

Bases: Url

Extension of the URL field that can handle file and data URLs

deserialize(value: Any, attr: str | None = None, data: Mapping[str, Any] | None = None, **kwargs)

Deserialize value.

Parameters:
  • value – The value to deserialize.

  • attr – The attribute/key in data to deserialize.

  • data – The raw input data passed to Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises:

ValidationError – If an invalid value is passed or if a required value is missing.

class qhana_plugin_runner.api.util.FileUrlValidator(*, relative: bool = False, absolute: bool = True, schemes: Sequence[str] | AbstractSet[str] | None = None, require_tld: bool = True, error: str | None = None)

Bases: URL

Extension of the URL validator that can handle file and data URLs

default_schemes = {'data', 'file', 'ftp', 'ftps', 'http', 'https'}
class qhana_plugin_runner.api.util.FrontendFormBaseSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool = False, context: Dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] = False, unknown: str | None = None, validate_errors_as_result: bool = False)

Bases: MaBaseSchema

Base schema for micro frontend forms that may be partially filled or contain errors.

Schemas inherited from this class retain their field order.

Set validate_errors_as_result=True to get the result of the validate() function in the endpoint instead of the parsed data.

class Meta

Bases: object

ordered = True
load(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

New in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>
class qhana_plugin_runner.api.util.HtmlResponseMixin

Bases: object

Extend Blueprint to add html response documentation.

html_response(status_code: int | str | HTTPStatus, *, description: str | None = None, example=None, examples=None, headers: dict | None = None, success=True)

Decorator documenting a html response adapted from ResponseMixin.alt_response().

Parameters:
  • status_code (int|str|HTTPStatus) – HTTP status code.

  • description (str, optional) – Description of the response. Defaults to None.

  • example (dict, optional) – Example of response message. Defaults to None.

  • examples (dict, optional) – Examples of response message. Defaults to None.

  • headers (dict, optional) – Headers returned by the response. Defaults to None.

class qhana_plugin_runner.api.util.MaBaseSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool = False, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)

Bases: Schema

Base schema that automatically changes python snake case to camelCase in json.

on_bind_field(field_name: str, field_obj: Field)

Hook to modify a field when it is bound to the Schema.

No-op by default.

opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>
class qhana_plugin_runner.api.util.PluginUrl(*, relative: bool = False, schemes: Sequence[str] | AbstractSet[str] | None = None, require_tld: bool = True, plugin_tags: Sequence[str] | str | None = None, plugin_name: str | None = None, plugin_version: str | None = None, required: bool = False, allow_none: bool = False, **kwargs)

Bases: Url

Extension of the URL field that can handle plugin URLs

deserialize(value: Any, attr: str | None = None, data: Mapping[str, Any] | None = None, **kwargs)

Deserialize value.

Parameters:
  • value – The value to deserialize.

  • attr – The attribute/key in data to deserialize.

  • data – The raw input data passed to Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises:

ValidationError – If an invalid value is passed or if a required value is missing.

class qhana_plugin_runner.api.util.SecurityBlueprint(*args: Any, **kwargs)

Bases: Blueprint, JWTMixin, HtmlResponseMixin

Blueprint that is aware of jwt tokens and how to document them.

Use this Blueprint if you want to document security requirements for your api.

qhana_plugin_runner.api.util.camelcase(s: str) str

Turn a string from python snake_case into camelCase.