uapi package#

Subpackages#

Submodules#

uapi.aiohttp module#

class uapi.aiohttp.AiohttpApp(converter=_Nothing.NOTHING, incant=_Nothing.NOTHING, route_map=_Nothing.NOTHING, openapi_security=_Nothing.NOTHING, framework_incant=_Nothing.NOTHING)#

Bases: App

Method generated by attrs for class AiohttpApp.

Parameters:
  • converter (Converter) –

  • incant (Incanter) –

  • route_map (dict[tuple[Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'], str], tuple[~collections.abc.Callable, ~uapi.types.RouteName, ~collections.abc.Sequence[str]]]) –

  • openapi_security (list[OpenAPISecuritySpec]) –

  • framework_incant (Incanter) –

framework_incant: Incanter#
async run(port=8000, host=None, handle_signals=True, shutdown_timeout=60, access_log=<Logger aiohttp.access (WARNING)>, handler_cancellation=False)#

Start serving this app.

If handle_signals is False, cancel the task running this to shut down.

Parameters:
  • handle_signals (bool) – Whether to let the underlying server handle signals.

  • port (int) –

  • host (str | None) –

  • shutdown_timeout (float) –

  • access_log (Logger | None) –

  • handler_cancellation (bool) –

to_framework_routes()#
Return type:

RouteTableDef

uapi.aiohttp.App#

alias of AiohttpApp

uapi.base module#

class uapi.base.App(converter=_Nothing.NOTHING, incant=_Nothing.NOTHING, route_map=_Nothing.NOTHING, openapi_security=_Nothing.NOTHING)#

Bases: object

A base _uapi_ App.

Use this class directly when creating reusable apps, or subclass it to create a framework-specific app.

Otherwise, an existing framework-specific app should be used.

Method generated by attrs for class App.

Parameters:
  • converter (Converter) –

  • incant (Incanter) –

  • route_map (dict[tuple[Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'], str], tuple[~collections.abc.Callable, ~uapi.types.RouteName, ~collections.abc.Sequence[str]]]) –

  • openapi_security (list[OpenAPISecuritySpec]) –

converter: Converter#
delete(path, name=None, tags=())#
Parameters:
  • path (str) –

  • name (str | None) –

  • tags (Sequence[str]) –

get(path, name=None, tags=())#
Parameters:
  • path (str) –

  • name (str | None) –

  • tags (Sequence[str]) –

head(path, name=None, tags=())#
Parameters:
  • path (str) –

  • name (str | None) –

  • tags (Sequence[str]) –

incant: Incanter#

The incanter used to compose handlers and middleware.

make_openapi_spec(title='Server', version='1.0', exclude={}, summary_transformer=<function default_summary_transformer>, description_transformer=<function default_description_transformer>)#

Create the OpenAPI spec for the registered routes.

Parameters:
  • exclude (set[str]) – A set of route names to exclude from the spec.

  • summary_transformer (Callable[[Callable, str], str | None]) – A function to map handlers and route names to OpenAPI PathItem summary strings.

  • description_transformer (Callable[[Callable, str], str | None]) – A function to map handlers and route names to OpenAPI PathItem description strings.

  • title (str) –

  • version (str) –

Return type:

OpenAPI

options(path, name=None, tags=())#
Parameters:
  • path (str) –

  • name (str | None) –

  • tags (Sequence[str]) –

patch(path, name=None, tags=())#
Parameters:
  • path (str) –

  • name (str | None) –

  • tags (Sequence[str]) –

post(path, name=None, tags=())#
Parameters:
  • path (str) –

  • name (str | None) –

  • tags (Sequence[str]) –

put(path, name=None, tags=())#
Parameters:
  • path (str) –

  • name (str | None) –

  • tags (Sequence[str]) –

route(path, handler, methods=['GET'], name=None, tags=())#

Register routes. This is not a decorator.

Parameters:
  • tags (Sequence[str]) – The OpenAPI tags to apply.

  • path (str) –

  • methods (Sequence[Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']]) –

  • name (str | None) –

route_app(app, prefix=None, name_prefix=None)#

Register all routes from a different app under an optional path prefix.

Parameters:
  • app (App) –

  • prefix (str | None) –

  • name_prefix (str | None) –

Return type:

None

serve_elements(path='/elements', openapi_path='/openapi.json')#

Start serving the OpenAPI Elements UI at the given path.

Parameters:
  • path (str) –

  • openapi_path (str) –

serve_openapi(title='Server', path='/openapi.json', exclude={}, summary_transformer=<function default_summary_transformer>, description_transformer=<function default_description_transformer>)#

Create the OpenAPI spec and start serving it at the given path.

Parameters:
  • exclude (set[str]) – A set of route names to exclude from the spec.

  • summary_transformer (Callable[[Callable, str], str | None]) – A function to map handlers and route names to OpenAPI PathItem summary strings.

  • description_transformer (Callable[[Callable, str], str | None]) – A function to map handlers and route names to OpenAPI PathItem description strings.

  • title (str) –

  • path (str) –

serve_redoc(path='/redoc', openapi_path='/openapi.json')#

Start serving the ReDoc UI at the given path.

Parameters:
  • path (str) –

  • openapi_path (str) –

serve_swaggerui(path='/swaggerui', openapi_path='/openapi.json')#

Start serving the Swagger UI at the given path.

Parameters:
  • path (str) –

  • openapi_path (str) –

class uapi.base.OpenAPISecuritySpec(security_scheme)#

Bases: object

Method generated by attrs for class OpenAPISecuritySpec.

Parameters:

security_scheme (ApiKeySecurityScheme) –

security_scheme: ApiKeySecurityScheme#
uapi.base.make_base_incanter()#

Create the base (non-framework) incanter.

Return type:

Incanter

uapi.cookies module#

class uapi.cookies.Cookie#

Bases: str

class uapi.cookies.CookieSettings(max_age=None, http_only=True, secure=True, path=None, domain=None, same_site='lax')#

Bases: object

Method generated by attrs for class CookieSettings.

Parameters:
  • max_age (int | None) –

  • http_only (bool) –

  • secure (bool) –

  • path (str | None) –

  • domain (str | None) –

  • same_site (Literal['strict', 'lax', 'none']) –

domain: str | None#
http_only: bool#
max_age: int | None#
path: str | None#
same_site: Literal['strict', 'lax', 'none']#
secure: bool#

Produce headers that should be returned as part of a response to set the cookie.

Parameters:
  • value (str | None) – When None, the cookie will be deleted.

  • name (str) –

  • settings (CookieSettings) –

Return type:

dict[str, str]

uapi.django module#

uapi.django.App#

alias of DjangoApp

class uapi.django.DjangoApp(converter=_Nothing.NOTHING, incant=_Nothing.NOTHING, route_map=_Nothing.NOTHING, openapi_security=_Nothing.NOTHING, framework_incant=_Nothing.NOTHING)#

Bases: App

Method generated by attrs for class DjangoApp.

Parameters:
  • converter (Converter) –

  • incant (Incanter) –

  • route_map (dict[tuple[Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'], str], tuple[~collections.abc.Callable, ~uapi.types.RouteName, ~collections.abc.Sequence[str]]]) –

  • openapi_security (list[OpenAPISecuritySpec]) –

  • framework_incant (Incanter) –

framework_incant: Incanter#
to_urlpatterns()#
Return type:

list[URLPattern]

uapi.flask module#

uapi.flask.App#

alias of FlaskApp

class uapi.flask.FlaskApp(converter=_Nothing.NOTHING, incant=_Nothing.NOTHING, route_map=_Nothing.NOTHING, openapi_security=_Nothing.NOTHING, framework_incant=_Nothing.NOTHING)#

Bases: App

Method generated by attrs for class FlaskApp.

Parameters:
  • converter (Converter) –

  • incant (Incanter) –

  • route_map (dict[tuple[Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'], str], tuple[~collections.abc.Callable, ~uapi.types.RouteName, ~collections.abc.Sequence[str]]]) –

  • openapi_security (list[OpenAPISecuritySpec]) –

  • framework_incant (Incanter) –

framework_incant: Incanter#
run(import_name, port=8000)#
Parameters:
  • import_name (str) –

  • port (int) –

to_framework_app(import_name)#
Parameters:

import_name (str) –

Return type:

Flask

uapi.openapi module#

class uapi.openapi.ApiKeySecurityScheme(name, in_, description=None, type='apiKey')#

Bases: object

Method generated by attrs for class ApiKeySecurityScheme.

Parameters:
  • name (str) –

  • in_ (Literal['query', 'header', 'cookie']) –

  • description (str | None) –

  • type (Literal['apiKey']) –

description: str | None#
in_: Literal['query', 'header', 'cookie']#
name: str#
type: Literal['apiKey']#
class uapi.openapi.ArraySchema(items, type=Type.ARRAY)#

Bases: object

Method generated by attrs for class ArraySchema.

Parameters:
items: Schema | Reference#
type: Literal[Schema.Type.ARRAY]#
class uapi.openapi.MediaType(schema)#

Bases: object

Method generated by attrs for class MediaType.

Parameters:

schema (Schema | OneOfSchema | ArraySchema | Reference) –

schema: Schema | OneOfSchema | ArraySchema | Reference#
class uapi.openapi.OneOfSchema(oneOf)#

Bases: object

Method generated by attrs for class OneOfSchema.

Parameters:

oneOf (Sequence[Reference | Schema]) –

oneOf: Sequence[Reference | Schema]#
class uapi.openapi.OpenAPI(openapi, info, paths, components)#

Bases: object

Method generated by attrs for class OpenAPI.

Parameters:
class Components(schemas, securitySchemes=_Nothing.NOTHING)#

Bases: object

Method generated by attrs for class OpenAPI.Components.

Parameters:
schemas: dict[str, Schema | ArraySchema | OneOfSchema | Reference]#
securitySchemes: Mapping[str, ApiKeySecurityScheme]#
class Info(title, version)#

Bases: object

Method generated by attrs for class OpenAPI.Info.

Parameters:
  • title (str) –

  • version (str) –

title: str#
version: str#
class Path#

Bases: object

Method generated by attrs for class OpenAPI.Path.

class PathItem(get=None, post=None, put=None, patch=None, delete=None)#

Bases: object

Method generated by attrs for class OpenAPI.PathItem.

Parameters:
class Operation(responses, parameters=_Nothing.NOTHING, requestBody=None, security=_Nothing.NOTHING, summary=None, tags=_Nothing.NOTHING, operationId=None, description=None)#

Bases: object

Method generated by attrs for class OpenAPI.PathItem.Operation.

Parameters:
  • responses (dict[str, Response]) –

  • parameters (list[Parameter]) –

  • requestBody (RequestBody | None) –

  • security (list[dict[str, list[str]]]) –

  • summary (str | None) –

  • tags (list[str]) –

  • operationId (str | None) –

  • description (str | None) –

description: str | None#
operationId: str | None#
parameters: list[Parameter]#
requestBody: RequestBody | None#
responses: dict[str, Response]#
security: list[dict[str, list[str]]]#
summary: str | None#
tags: list[str]#
delete: Operation | None#
get: Operation | None#
patch: Operation | None#
post: Operation | None#
put: Operation | None#
components: Components#
info: Info#
openapi: str#
paths: dict[str, PathItem]#
class uapi.openapi.Parameter(name, kind, required=False, schema=None)#

Bases: object

Method generated by attrs for class Parameter.

Parameters:
class Kind(value)#

Bases: str, Enum

An enumeration.

COOKIE = 'cookie'#
HEADER = 'header'#
PATH = 'path'#
QUERY = 'query'#
kind: Kind#
name: str#
required: bool#
schema: Schema | Reference | OneOfSchema | None#
class uapi.openapi.Reference(ref)#

Bases: object

Method generated by attrs for class Reference.

Parameters:

ref (str) –

ref: str#
class uapi.openapi.RequestBody(content, description=None, required=False)#

Bases: object

Method generated by attrs for class RequestBody.

Parameters:
  • content (Mapping[str, MediaType]) –

  • description (str | None) –

  • required (bool) –

content: Mapping[str, MediaType]#
description: str | None#
required: bool#
class uapi.openapi.Response(description, content=_Nothing.NOTHING)#

Bases: object

Method generated by attrs for class Response.

Parameters:
  • description (str) –

  • content (dict[str, MediaType]) –

content: dict[str, MediaType]#
description: str#
class uapi.openapi.Schema(type, properties=None, format=None, additionalProperties=False, enum=None, required=_Nothing.NOTHING)#

Bases: object

Method generated by attrs for class Schema.

Parameters:
  • type (Type) –

  • properties (dict[str, AnySchema | Reference] | None) –

  • format (str | None) –

  • additionalProperties (bool | Schema | Reference) –

  • enum (list[str] | None) –

  • required (list[str]) –

class Type(value)#

Bases: Enum

An enumeration.

ARRAY = 'array'#
BOOLEAN = 'boolean'#
INTEGER = 'integer'#
NULL = 'null'#
NUMBER = 'number'#
OBJECT = 'object'#
STRING = 'string'#
additionalProperties: bool | Schema | Reference#
enum: list[str] | None#
format: str | None#
properties: dict[str, AnySchema | Reference] | None#
required: list[str]#
type: Type#
uapi.openapi.build_operation(handler, original_handler, name, path, components, path_param_parser, framework_req_cls, framework_resp_cls, security_schemas, summary_transformer, description_transformer, tags)#
Parameters:
  • handler (Callable) –

  • original_handler (Callable) –

  • name (str) –

  • path (str) –

  • components (dict[type, str]) –

  • path_param_parser (Callable[[str], tuple[str, list[str]]]) –

  • framework_req_cls (type | None) –

  • framework_resp_cls (type | None) –

  • security_schemas (Mapping[str, ApiKeySecurityScheme]) –

  • summary_transformer (Callable[[Callable, str], str | None]) –

  • description_transformer (Callable[[Callable, str], str | None]) –

  • tags (list[str]) –

Return type:

Operation

uapi.openapi.build_pathitem(path, path_routes, components, path_param_parser, framework_req_cls, framework_resp_cls, security_schemas, summary_transformer, description_transformer)#
Parameters:
  • path (str) –

  • path_routes (dict[Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'], tuple[~collections.abc.Callable, ~collections.abc.Callable, ~uapi.types.RouteName, ~collections.abc.Sequence[str]]]) –

  • components (dict[type, str]) –

  • path_param_parser (Callable[[str], tuple[str, list[str]]]) –

  • framework_req_cls (type | None) –

  • framework_resp_cls (type | None) –

  • security_schemas (Mapping[str, ApiKeySecurityScheme]) –

  • summary_transformer (Callable[[Callable, str], str | None]) –

  • description_transformer (Callable[[Callable, str], str | None]) –

Return type:

PathItem

uapi.openapi.components_to_openapi(routes, security_schemes={})#

Build the components part.

Components are complex structures, like classes, as opposed to primitives like ints.

Parameters:
  • routes (dict[tuple[Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'], str], tuple[~collections.abc.Callable, ~collections.abc.Callable, ~uapi.types.RouteName, ~collections.abc.Sequence[str]]]) –

  • security_schemes (dict[str, ApiKeySecurityScheme]) –

Return type:

tuple[Components, dict[type, str]]

uapi.openapi.default_description_transformer(handler, name)#

Use the handler docstring, if present.

Parameters:
  • handler (Callable) –

  • name (str) –

Return type:

str | None

uapi.openapi.default_summary_transformer(handler, name)#
Parameters:
  • handler (Callable) –

  • name (str) –

Return type:

str

uapi.openapi.gather_endpoint_components(handler, components)#
Parameters:
  • handler (Callable) –

  • components (dict[type, str]) –

Return type:

dict[type, str]

uapi.openapi.make_openapi_spec(routes, path_param_parser, title='Server', version='1.0', framework_req_cls=None, framework_resp_cls=None, security_schemes=[], summary_transformer=<function default_summary_transformer>, description_transformer=<function default_description_transformer>)#
Parameters:
  • routes (dict[tuple[Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'], str], tuple[~collections.abc.Callable, ~collections.abc.Callable, ~uapi.types.RouteName, ~collections.abc.Sequence[str]]]) –

  • path_param_parser (Callable[[str], tuple[str, list[str]]]) –

  • title (str) –

  • version (str) –

  • framework_req_cls (type | None) –

  • framework_resp_cls (type | None) –

  • security_schemes (list[ApiKeySecurityScheme]) –

  • summary_transformer (Callable[[Callable, str], str | None]) –

  • description_transformer (Callable[[Callable, str], str | None]) –

Return type:

OpenAPI

uapi.openapi.routes_to_paths(routes, components, path_param_parser, framework_req_cls, framework_resp_cls, security_schemas, summary_transformer, description_transformer)#
Parameters:
  • routes (dict[tuple[Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'], str], tuple[~collections.abc.Callable, ~collections.abc.Callable, ~uapi.types.RouteName, ~collections.abc.Sequence[str]]]) –

  • components (dict[type, str]) –

  • path_param_parser (Callable[[str], tuple[str, list[str]]]) –

  • framework_req_cls (type | None) –

  • framework_resp_cls (type | None) –

  • security_schemas (Mapping[str, ApiKeySecurityScheme]) –

  • summary_transformer (Callable[[Callable, str], str | None]) –

  • description_transformer (Callable[[Callable, str], str | None]) –

Return type:

dict[str, PathItem]

uapi.openapi.structure_inlinetype_ref(val, _)#
uapi.openapi.structure_schemas(val, _)#

uapi.path module#

For path parameters.

uapi.path.angle_to_curly(path)#
Parameters:

path (str) –

Return type:

str

uapi.path.parse_angle_path_params(path_str)#
Parameters:

path_str (str) –

Return type:

list[str]

uapi.path.parse_curly_path_params(path_str)#
Parameters:

path_str (str) –

Return type:

list[str]

uapi.path.strip_path_param_prefix(path)#
Parameters:

path (str) –

Return type:

str

uapi.quart module#

uapi.quart.App#

alias of QuartApp

class uapi.quart.QuartApp(converter=_Nothing.NOTHING, incant=_Nothing.NOTHING, route_map=_Nothing.NOTHING, openapi_security=_Nothing.NOTHING, framework_incant=_Nothing.NOTHING)#

Bases: App

Method generated by attrs for class QuartApp.

Parameters:
  • converter (Converter) –

  • incant (Incanter) –

  • route_map (dict[tuple[Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'], str], tuple[~collections.abc.Callable, ~uapi.types.RouteName, ~collections.abc.Sequence[str]]]) –

  • openapi_security (list[OpenAPISecuritySpec]) –

  • framework_incant (Incanter) –

framework_incant: Incanter#
async run(import_name, port=8000, handle_signals=True, log_level=None)#

Start serving this app using uvicorn.

Cancel the task running this to shut down uvicorn.

Parameters:
  • import_name (str) –

  • port (int) –

  • handle_signals (bool) –

  • log_level (str | int | None) –

Return type:

None

to_framework_app(import_name)#
Parameters:

import_name (str) –

Return type:

Quart

uapi.requests module#

uapi.requests.FormBody#

A form in the request body.

alias of T[T]

class uapi.requests.FormSpec#

Bases: object

Metadata for loading forms.

Method generated by attrs for class FormSpec.

uapi.requests.Header#

A header dependency.

alias of T[T]

class uapi.requests.HeaderSpec(name=<function HeaderSpec.<lambda>>)#

Bases: object

Metadata for loading headers.

Method generated by attrs for class HeaderSpec.

Parameters:

name (str | Callable[[str], str]) –

name: str | Callable[[str], str]#
class uapi.requests.JsonBodyLoader(content_type='application/json', error_handler=<function JsonBodyLoader.<lambda>>)#

Bases: object

Metadata for customized loading and structuring of JSON bodies.

Method generated by attrs for class JsonBodyLoader.

Parameters:
  • content_type (str | None) –

  • error_handler (Callable[[Exception, bytes], BaseResponse]) –

content_type: str | None#
error_handler: Callable[[Exception, bytes], BaseResponse]#
uapi.requests.attrs_body_factory(parameter, converter)#
Parameters:
  • parameter (Parameter) –

  • converter (Converter) –

Return type:

Callable[[ReqBytes], Any]

Parameters:

arg_name (str) –

Return type:

str | None

uapi.requests.get_form_type(p)#
Parameters:

p (Parameter) –

Return type:

type

uapi.requests.get_header_type(p)#

Similar to maybe_req_body_attrs, except raises.

Parameters:

p (Parameter) –

Return type:

tuple[type, HeaderSpec]

uapi.requests.get_req_body_attrs(p)#

Similar to maybe_req_body_attrs, except raises.

Parameters:

p (Parameter) –

Return type:

tuple[type, JsonBodyLoader]

uapi.requests.is_form(p)#

Is this parameter a form?

Parameters:

p (Parameter) –

Return type:

bool

uapi.requests.is_header(p)#
Parameters:

p (Parameter) –

Return type:

bool

uapi.requests.is_req_body_attrs(p)#
Parameters:

p (Parameter) –

Return type:

bool

uapi.requests.maybe_form_type(p)#

Get the underlying form type, is present.

Parameters:

p (Parameter) –

Return type:

type | None

uapi.requests.maybe_header_type(p)#

Get the Annotated HeaderSpec, if present.

Parameters:

p (Parameter) –

Return type:

tuple[type, HeaderSpec] | None

uapi.requests.maybe_req_body_type(p)#

Is this parameter a valid request body?

Parameters:

p (Parameter) –

Return type:

tuple[type, JsonBodyLoader] | None

uapi.responses module#

uapi.responses.dumps(obj, /, default=None, option=None)#

Serialize Python objects to JSON.

uapi.responses.get_status_code_results(t)#

Normalize a supported return type into (status code, type).

Parameters:

t (type) –

Return type:

list[tuple[int, Any]]

uapi.responses.return_type_to_statuses(t)#
Parameters:

t (type) –

Return type:

dict[int, Any]

uapi.starlette module#

uapi.starlette.App#

alias of StarletteApp

class uapi.starlette.StarletteApp(converter=_Nothing.NOTHING, incant=_Nothing.NOTHING, route_map=_Nothing.NOTHING, openapi_security=_Nothing.NOTHING, framework_incant=_Nothing.NOTHING)#

Bases: App

Method generated by attrs for class StarletteApp.

Parameters:
  • converter (Converter) –

  • incant (Incanter) –

  • route_map (dict[tuple[Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'], str], tuple[~collections.abc.Callable, ~uapi.types.RouteName, ~collections.abc.Sequence[str]]]) –

  • openapi_security (list[OpenAPISecuritySpec]) –

  • framework_incant (Incanter) –

framework_incant: Incanter#
async run(port=8000, handle_signals=True, log_level=None)#

Start serving this app using uvicorn.

Cancel the task running this to shut down uvicorn.

Parameters:
  • port (int) –

  • handle_signals (bool) –

  • log_level (str | int | None) –

Return type:

None

to_framework_app()#
Return type:

Starlette

uapi.status module#

Status code classes for return values.

class uapi.status.BadRequest(ret, headers=_Nothing.NOTHING)#

Bases: BaseResponse[Literal[400], R]

Method generated by attrs for class BadRequest.

Parameters:
  • ret (R) –

  • headers (dict[str, str]) –

class uapi.status.BaseResponse(ret, headers=_Nothing.NOTHING)#

Bases: Generic[S, R]

Method generated by attrs for class BaseResponse.

Parameters:
  • ret (R) –

  • headers (dict[str, str]) –

headers: dict[str, str]#
ret: R#
classmethod status_code()#
Return type:

int

class uapi.status.Created(ret, headers=_Nothing.NOTHING)#

Bases: BaseResponse[Literal[201], R]

Method generated by attrs for class Created.

Parameters:
  • ret (R) –

  • headers (dict[str, str]) –

class uapi.status.Forbidden(ret, headers=_Nothing.NOTHING)#

Bases: BaseResponse[Literal[403], R]

Method generated by attrs for class Forbidden.

Parameters:
  • ret (R) –

  • headers (dict[str, str]) –

class uapi.status.Found(ret, headers=_Nothing.NOTHING)#

Bases: BaseResponse[Literal[302], R]

Method generated by attrs for class Found.

Parameters:
  • ret (R) –

  • headers (dict[str, str]) –

class uapi.status.InternalServerError(ret, headers=_Nothing.NOTHING)#

Bases: BaseResponse[Literal[500], R]

Method generated by attrs for class InternalServerError.

Parameters:
  • ret (R) –

  • headers (dict[str, str]) –

class uapi.status.NoContent(headers=_Nothing.NOTHING, ret=None)#

Bases: BaseResponse[Literal[204], None]

Method generated by attrs for class NoContent.

Parameters:
  • headers (dict[str, str]) –

  • ret (None) –

ret: None#
classmethod status_code()#
Return type:

int

class uapi.status.NotFound(ret, headers=_Nothing.NOTHING)#

Bases: BaseResponse[Literal[404], R]

Method generated by attrs for class NotFound.

Parameters:
  • ret (R) –

  • headers (dict[str, str]) –

class uapi.status.Ok(ret, headers=_Nothing.NOTHING)#

Bases: BaseResponse[Literal[200], R]

Method generated by attrs for class Ok.

Parameters:
  • ret (R) –

  • headers (dict[str, str]) –

class uapi.status.SeeOther(ret, headers=_Nothing.NOTHING)#

Bases: BaseResponse[Literal[303], R]

Method generated by attrs for class SeeOther.

Parameters:
  • ret (R) –

  • headers (dict[str, str]) –

uapi.types module#

uapi.types.Method#

The HTTP request method.

alias of Literal[‘GET’, ‘POST’, ‘PUT’, ‘PATCH’, ‘DELETE’, ‘HEAD’, ‘OPTIONS’]

class uapi.types.RouteName#

The route name.

alias of str

uapi.types.is_subclass(cls, subclass)#

A more robust version.

Return type:

bool

Module contents#

class uapi.Cookie#

Bases: str

class uapi.HeaderSpec(name=<function HeaderSpec.<lambda>>)#

Bases: object

Metadata for loading headers.

Method generated by attrs for class HeaderSpec.

Parameters:

name (str | Callable[[str], str]) –

name: str | Callable[[str], str]#
exception uapi.ResponseException(response)#

Bases: Exception

An exception that is converted into an HTTP response.

Method generated by attrs for class ResponseException.

Parameters:

response (BaseResponse) –

Return type:

None

response: BaseResponse#
uapi.redirect(location, headers={})#
Parameters:
  • location (str) –

  • headers (dict[str, str]) –

Return type:

Found[None]

uapi.redirect_to_get(location, headers={})#
Parameters:
  • location (str) –

  • headers (dict[str, str]) –

Return type:

SeeOther[None]