qunicorn_core.api package

Subpackages

Submodules

qunicorn_core.api.flask_api_utils module

Module containing utilities for flask smorest APIs.

class qunicorn_core.api.flask_api_utils.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 qunicorn_core.api.flask_api_utils.SecurityBlueprint(*args: Any, **kwargs)

Bases: Blueprint, JWTMixin

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.

qunicorn_core.api.flask_api_utils.camelcase(s: str) str

Turn a string from python snake_case into camelCase.

qunicorn_core.api.jwt module

Module containing JWT security features for the API.

class qunicorn_core.api.jwt.JWTMixin

Bases: object

Extend Blueprint to add security documentation and jwt handling

require_jwt(security_scheme: str | Dict[str, List[Any]] = 'jwt', optional: bool = False) Callable[[Callable[[...], RT]], Callable[[...], RT]]

Decorator validating jwt tokens and documenting them for openapi specification (only version 3…).

qunicorn_core.api.jwt.JWT_SCHEME = {'bearerFormat': 'JWT', 'description': 'The jwt access token as returned by login or refresh.', 'scheme': 'bearer', 'type': 'http'}

Security schemes to be added to the swagger.json api documentation.

qunicorn_core.api.jwt.abort_if_user_unauthorized(user_from_data_object: str | None, logged_in_user_id: str)

If the user_from_data_object is None everybody can access it. If the user_from_data_object is not None, only the correct user can access it -> Otherwise abort.

Module contents

Module containing all API related code of the project.

class qunicorn_core.api.RootView

Bases: MethodView

get() Dict[str, str]

Get the Root API information containing the links to all versions of this api.

methods: t.ClassVar[t.Collection[str] | None] = {'GET'}

The methods this view is registered for. Uses the same default (["GET", "HEAD", "OPTIONS"]) as route and add_url_rule by default.

class qunicorn_core.api.VersionsRootSchema(*, 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: MaBaseSchema

opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>
qunicorn_core.api.register_root_api(app: Flask)

Register the API with the flask app.