ft3.api package

Api Overview

Author: dan@1howardcapital.com

Summary: Api module.

Usage

$ ft3 api ${PACKAGE_NAME}
api_from_package(name: str, version: str, api_path: str, include_heartbeat: bool = True, include_version_prefix: bool = False, include_default_response_headers: bool = True, lazy_docs: bool = True) Api

Generate a RESTful API from passed python package name.

runtime_api_from_package(name: str, version: str, api_path: str, include_heartbeat: bool = True, include_version_prefix: bool = False, include_default_response_headers: bool = True) Api

Generate a RESTful API with only runtime dispatch metadata.

class Api(class_as_dict: dict[str | string[StringType], Any] | None = None, /, **kwargs: Any)

Bases: Component

OpenAPI OpenAPI Object.

info: Field[Info]
openapi: Field[str]
paths: Field[dict[str, Path]]
tags: Field[list[Tag]]
servers: Field[list[ServerObject] | None]
components: Field[dict[str, dict[str, Any]] | None]
enumerations: lib.t.ClassVar[dict[str, tuple[typ.Primitive, ...]]] = {}
fields: lib.t.ClassVar[typ.FieldsTuple] = ('_ref_', 'components', 'info', 'openapi', 'paths', 'servers', 'tags')
hash_fields: lib.t.ClassVar[typ.FieldsTuple] = ()
classmethod register(obj_: type[ObjectType]) type[ObjectType]

Register an Object to be served from the API.

class_as_dict: lib.t.Final[lib.t.Optional[dict[typ.AnyString, lib.t.Any]]] = {}

Instantiate class directly from passed dict (assumed to be version of class in dict form).

class File(class_as_dict: dict[str | string[StringType], Any] | None = None, /, **kwargs: Any)

Bases: Object

A file object, useful for serving static files.

path: Field[str]

The path at which to serve the file.

content: Field[bytes | str]

File content.

content_type: Field[str]
enumerations: lib.t.ClassVar[dict[str, tuple[typ.Primitive, ...]]] = {}
fields: lib.t.ClassVar[typ.FieldsTuple] = ('content', 'content_type', 'path')
hash_fields: lib.t.ClassVar[typ.FieldsTuple] = ()
class_as_dict: lib.t.Final[lib.t.Optional[dict[typ.AnyString, lib.t.Any]]] = {}

Instantiate class directly from passed dict (assumed to be version of class in dict form).

class Handler(class_as_dict: dict[str | string[StringType], Any] | None = None, /, **kwargs: Any)

Bases: Object

A simple request handler.

api: Field[Api]
file_paths: Field[list[str]]
enumerations: lib.t.ClassVar[dict[str, tuple[typ.Primitive, ...]]] = {}
fields: lib.t.ClassVar[typ.FieldsTuple] = ('api', 'file_paths')
hash_fields: lib.t.ClassVar[typ.FieldsTuple] = ()
class Header(class_as_dict: dict[str | string[StringType], Any] | None = None, /, **kwargs: Any)

Bases: Component

OpenAPI Header Object.

description: Field[str | None]
schema: Field[Schema | None]
enumerations: lib.t.ClassVar[dict[str, tuple[typ.Primitive, ...]]] = {}
fields: lib.t.ClassVar[typ.FieldsTuple] = ('_ref_', 'description', 'schema')
hash_fields: lib.t.ClassVar[typ.FieldsTuple] = ()
classmethod request(name: str, description: str | None, *methods: str) Callable[[type[ObjectType]], type[ObjectType]]

Register a request header for Object.

classmethod response(name: str, description: str | None, *methods: str) Callable[[type[ObjectType]], type[ObjectType]]

Register a response header for Object.

class Request(class_as_dict: dict[str | string[StringType], Any] | None = None, /, **kwargs: Any)

Bases: Object

A simple request object.

id_: Field[str]
url: Field[str]
path: Field[str]
method: Field[str]
headers: Field[dict[str, str]]
body: Field[Any]
path_params: Field[dict[str | string[StringType], str]]
query_params: Field[dict[str | string[StringType], Any]]
enumerations: lib.t.ClassVar[dict[str, tuple[typ.Primitive, ...]]] = {}
fields: lib.t.ClassVar[typ.FieldsTuple] = ('body', 'headers', 'id_', 'method', 'path', 'path_params', 'query_params', 'url')
hash_fields: lib.t.ClassVar[typ.FieldsTuple] = ('id_',)
parse_body(operation: Operation, obj_: type[objects.Object] | None = None) Never | None

Parse JSON body from url string and optionally an Object.

Automatically handles translation and injection of id params for PUT requests.

parse_path_params(uri: str, operation: Operation) None

Parse path parameters from a matched path uri.

parse_query_params(method: string[snake_case], operation: Operation, obj_: type[objects.Object] | None = None) None

Parse query parameters from url string and optionally an Object.

class Response(class_as_dict: dict[str | string[StringType], Any] | None = None, /, **kwargs: Any)

Bases: Object

A simple response object.

request_id: Field[str]
status_code: Field[Literal[200, 201, 204, 301, 400, 401, 403, 404, 405, 423, 429, 500, 501]]
headers: Field[dict[str, str]]
body: Field[Any]
enumerations: lib.t.ClassVar[dict[str, tuple[typ.Primitive, ...]]] = {}
fields: lib.t.ClassVar[typ.FieldsTuple] = ('body', 'headers', 'request_id', 'status_code')
hash_fields: lib.t.ClassVar[typ.FieldsTuple] = ('request_id',)
serialize() bytes | str

JSON serialize body if not already a string.

class SecurityScheme(class_as_dict: dict[str | string[StringType], Any] | None = None, /, **kwargs: Any)

Bases: Component

OpenAPI Security Scheme Object.

type_: Field[str]
in_: Field[str | None]
scheme: Field[str | None]
name_: Field[str]
description: Field[str | None]
content: Field[dict[Literal['*/*', 'text/html', 'image/x-icon', 'application/json', 'image/png', 'text/plain'], Content]]
classmethod api_key(name: str, description: str | None, *methods: str) Callable[[type[ObjectType]], type[ObjectType]]

Register API Key SecurityScheme for Object.

enumerations: lib.t.ClassVar[dict[str, tuple[typ.Primitive, ...]]] = {'in_': ('header', 'query', 'cookie', None), 'scheme': ('basic', 'bearer', None), 'type_': ('http', 'apiKey', 'oauth2', 'openIdConnect')}
fields: lib.t.ClassVar[typ.FieldsTuple] = ('_ref_', 'content', 'description', 'in_', 'name_', 'scheme', 'type_')
hash_fields: lib.t.ClassVar[typ.FieldsTuple] = ('name_',)

Subpackages

Submodules