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:
Generic
[C_contra
],AsyncApp
[Union
[C_contra
,StreamResponse
]]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) –
- add_response_shorthand(shorthand)#
Add a response shorthand to the App.
Response shorthands enable additional return types for handlers.
The type will be matched by identity and an is_subclass check.
- Parameters:
type – The type to add to possible handler return annotations.
response_adapter – A callable, used to convert a value of the new type into a BaseResponse.
shorthand (type[ResponseShorthand[T_co]]) –
- Return type:
AiohttpApp[T_co | C_contra]
- 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.base module#
- class uapi.base.App(converter=_Nothing.NOTHING, incant=_Nothing.NOTHING, route_map=_Nothing.NOTHING, openapi_security=_Nothing.NOTHING)#
Bases:
Generic
[C
],_AppBase
A base _uapi_ synchronous 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]) –
- add_response_shorthand(shorthand)#
Add a response shorthand to the App.
Response shorthands enable additional return types for handlers.
The type will be matched by identity and an is_subclass check.
- Parameters:
type – The type to add to possible handler return annotations.
response_adapter – A callable, used to convert a value of the new type into a BaseResponse.
shorthand (type[ResponseShorthand[T_co]]) –
- Return type:
App[C | T_co]
- delete(path, name=None, tags=())#
- Parameters:
path (str) –
name (str | None) –
tags (Sequence[str]) –
- Return type:
Callable[[Callable[[…], BaseResponse | None | str | bytes | AttrsInstance | C]], Any]
- get(path, name=None, tags=())#
- Parameters:
path (str) –
name (str | None) –
tags (Sequence[str]) –
- Return type:
Callable[[Callable[[…], BaseResponse | None | str | bytes | AttrsInstance | C]], Any]
- head(path, name=None, tags=())#
- Parameters:
path (str) –
name (str | None) –
tags (Sequence[str]) –
- Return type:
Callable[[Callable[[…], BaseResponse | None | str | bytes | AttrsInstance | C]], Any]
- options(path, name=None, tags=())#
- Parameters:
path (str) –
name (str | None) –
tags (Sequence[str]) –
- Return type:
Callable[[Callable[[…], BaseResponse | None | str | bytes | AttrsInstance | C]], Any]
- patch(path, name=None, tags=())#
- Parameters:
path (str) –
name (str | None) –
tags (Sequence[str]) –
- Return type:
Callable[[Callable[[…], BaseResponse | None | str | bytes | AttrsInstance | C]], Any]
- post(path, name=None, tags=())#
- Parameters:
path (str) –
name (str | None) –
tags (Sequence[str]) –
- Return type:
Callable[[Callable[[…], BaseResponse | None | str | bytes | AttrsInstance | C]], Any]
- put(path, name=None, tags=())#
- Parameters:
path (str) –
name (str | None) –
tags (Sequence[str]) –
- Return type:
Callable[[Callable[[…], BaseResponse | None | str | bytes | AttrsInstance | C]], Any]
- route(path, handler, methods={'GET'}, name=None, tags=())#
Register routes. This is not a decorator.
- Parameters:
path (str) – The URL path on which to serve the handler.
handler (Callable[[...], BaseResponse | None | str | bytes | AttrsInstance | C]) – The handler to route to.
methods (Iterable[Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']]) – The HTTP methods on which to serve the handler.
name (str | None) – The route name. If not provided, will use the handler name.
tags (Sequence[str]) – The OpenAPI tags to apply.
- Return type:
Any
uapi.django module#
- class uapi.django.DjangoApp(converter=_Nothing.NOTHING, incant=_Nothing.NOTHING, route_map=_Nothing.NOTHING, openapi_security=_Nothing.NOTHING, framework_incant=_Nothing.NOTHING)#
Bases:
Generic
[C_contra
],App
[Union
[C_contra
,HttpResponse
]]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) –
- add_response_shorthand(shorthand)#
Add a response shorthand to the App.
Response shorthands enable additional return types for handlers.
The type will be matched by identity and an is_subclass check.
- Parameters:
type – The type to add to possible handler return annotations.
response_adapter – A callable, used to convert a value of the new type into a BaseResponse.
shorthand (type[ResponseShorthand[T_co]]) –
- Return type:
DjangoApp[T_co | C_contra]
- framework_incant: Incanter#
- to_urlpatterns()#
- Return type:
list[URLPattern]
uapi.flask module#
- class uapi.flask.FlaskApp(converter=_Nothing.NOTHING, incant=_Nothing.NOTHING, route_map=_Nothing.NOTHING, openapi_security=_Nothing.NOTHING, framework_incant=_Nothing.NOTHING)#
Bases:
Generic
[C_contra
],App
[Union
[C_contra
,Response
]]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, host=None, port=8000)#
Start serving the app using the Flask development server.
- Parameters:
import_name (str) –
host (str | None) –
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 | IntegerSchema | Reference) –
type (Literal[Schema.Type.ARRAY]) –
- items: Schema | IntegerSchema | Reference#
- type: Literal[Schema.Type.ARRAY]#
- class uapi.openapi.IntegerSchema(format=None, minimum=None, maximum=None, exclusiveMinimum=False, exclusiveMaximum=False, multipleOf=None, enum=_Nothing.NOTHING, type=Type.INTEGER)#
Bases:
object
Method generated by attrs for class IntegerSchema.
- Parameters:
format (Literal[None, 'int32', 'int64']) –
minimum (int | None) –
maximum (int | None) –
exclusiveMinimum (bool) –
exclusiveMaximum (bool) –
multipleOf (int | None) –
enum (list[int]) –
type (Literal[Schema.Type.INTEGER]) –
- enum: list[int]#
- exclusiveMaximum: bool#
- exclusiveMinimum: bool#
- format: Literal[None, 'int32', 'int64']#
- maximum: int | None#
- minimum: int | None#
- multipleOf: int | None#
- type: Literal[Schema.Type.INTEGER]#
- class uapi.openapi.MediaType(schema)#
Bases:
object
Method generated by attrs for class MediaType.
- Parameters:
schema (Schema | IntegerSchema | ArraySchema | OneOfSchema | Reference) –
- schema: Schema | IntegerSchema | ArraySchema | OneOfSchema | Reference#
- class uapi.openapi.OneOfSchema(oneOf)#
Bases:
object
Method generated by attrs for class OneOfSchema.
- Parameters:
oneOf (Sequence[Schema | IntegerSchema | ArraySchema | OneOfSchema | Reference]) –
- oneOf: Sequence[Schema | IntegerSchema | ArraySchema | OneOfSchema | Reference]#
- class uapi.openapi.OpenAPI(openapi, info, paths, components)#
Bases:
object
Method generated by attrs for class OpenAPI.
- Parameters:
openapi (str) –
info (Info) –
paths (dict[str, PathItem]) –
components (Components) –
- class Components(schemas, securitySchemes=_Nothing.NOTHING)#
Bases:
object
Method generated by attrs for class OpenAPI.Components.
- Parameters:
schemas (dict[str, Schema | IntegerSchema | ArraySchema | OneOfSchema | Reference]) –
securitySchemes (Mapping[str, ApiKeySecurityScheme]) –
- schemas: dict[str, Schema | IntegerSchema | 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#
- requestBody: RequestBody | None#
- security: list[dict[str, list[str]]]#
- summary: str | None#
- tags: list[str]#
- components: Components#
- openapi: str#
- class uapi.openapi.Parameter(name, kind, required=False, schema=None)#
Bases:
object
Method generated by attrs for class Parameter.
- class Kind(value)#
Bases:
str
,Enum
An enumeration.
- COOKIE = 'cookie'#
- HEADER = 'header'#
- PATH = 'path'#
- QUERY = 'query'#
- name: str#
- required: bool#
- 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) –
- 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]) –
- description: str#
- class uapi.openapi.Schema(type=None, properties=None, format=None, additionalProperties=False, enum=None, required=_Nothing.NOTHING)#
Bases:
object
The generic schema base class.
Consider using a specialized version (like IntegerSchema) instead.
Method generated by attrs for class Schema.
- Parameters:
type (Type | None) –
properties (dict[str, AnySchema | Reference] | None) –
format (str | None) –
additionalProperties (bool | Schema | IntegerSchema | 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 | IntegerSchema | Reference#
- enum: list[str] | None#
- format: str | None#
- required: list[str]#
- class uapi.openapi.SchemaBuilder(names=_Nothing.NOTHING, components=_Nothing.NOTHING, build_rules=_Nothing.NOTHING)#
Bases:
object
A helper builder for defining OpenAPI/JSON schemas.
Method generated by attrs for class SchemaBuilder.
- Parameters:
names (dict[type, str]) –
components (dict[str, Schema | IntegerSchema | ArraySchema | OneOfSchema | Reference]) –
build_rules (list[tuple[Callable[[Any], bool], Callable[[Any, SchemaBuilder], Schema | IntegerSchema | ArraySchema | OneOfSchema]]]) –
- PYTHON_PRIMITIVES_TO_OPENAPI: ClassVar[dict[type, Schema | IntegerSchema]] = {<class 'bool'>: Schema(type=<Type.BOOLEAN: 'boolean'>, properties=None, format=None, additionalProperties=False, enum=None, required=[]), <class 'bytes'>: Schema(type=<Type.STRING: 'string'>, properties=None, format='binary', additionalProperties=False, enum=None, required=[]), <class 'datetime.date'>: Schema(type=<Type.STRING: 'string'>, properties=None, format='date', additionalProperties=False, enum=None, required=[]), <class 'datetime.datetime'>: Schema(type=<Type.STRING: 'string'>, properties=None, format='date-time', additionalProperties=False, enum=None, required=[]), <class 'float'>: Schema(type=<Type.NUMBER: 'number'>, properties=None, format='double', additionalProperties=False, enum=None, required=[]), <class 'int'>: IntegerSchema(format=None, minimum=None, maximum=None, exclusiveMinimum=False, exclusiveMaximum=False, multipleOf=None, enum=[], type=<Type.INTEGER: 'integer'>), <class 'str'>: Schema(type=<Type.STRING: 'string'>, properties=None, format=None, additionalProperties=False, enum=None, required=[])}#
- build_rules: list[tuple[Callable[[Any], bool], Callable[[Any, SchemaBuilder], Schema | IntegerSchema | ArraySchema | OneOfSchema]]]#
- build_schema_from_rules(type)#
- Parameters:
type (Any) –
- Return type:
- components: dict[str, Schema | IntegerSchema | ArraySchema | OneOfSchema | Reference]#
- classmethod default_build_rules()#
Set up the default build rules.
- Return type:
list[tuple[Callable[[Any], bool], Callable[[Any, SchemaBuilder], Schema | IntegerSchema | ArraySchema | OneOfSchema]]]
- get_schema_for_type(type)#
- Parameters:
type (Any) –
- Return type:
- names: dict[type, str]#
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#
- class uapi.quart.QuartApp(converter=_Nothing.NOTHING, incant=_Nothing.NOTHING, route_map=_Nothing.NOTHING, openapi_security=_Nothing.NOTHING, framework_incant=_Nothing.NOTHING)#
Bases:
Generic
[C_contra
],AsyncApp
[Union
[C_contra
,Response
]]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) –
- add_response_shorthand(shorthand)#
Add a response shorthand to the App.
Response shorthands enable additional return types for handlers.
The type will be matched by identity and an is_subclass check.
- Parameters:
type – The type to add to possible handler return annotations.
response_adapter – A callable, used to convert a value of the new type into a BaseResponse.
shorthand (type[ResponseShorthand[T_co]]) –
- Return type:
QuartApp[T_co | C_contra]
- framework_incant: Incanter#
- async run(import_name, host='127.0.0.1', 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) –
host (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]
- uapi.requests.get_cookie_name(t, arg_name)#
- 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.dict_to_headers(d)#
- Parameters:
d (dict[str, str]) –
- Return type:
list[tuple[str, str]]
- uapi.responses.identity(x)#
The identity function, used and recognized for certain optimizations.
- Parameters:
x (T) –
- Return type:
T
- uapi.responses.make_exception_adapter(converter)#
Produce an adapter of exceptions to BaseResponses.
Since exception types aren’t statically known, this can be simpler than the return adapter.
- Parameters:
converter (Converter) –
- Return type:
Callable[[ResponseException], BaseResponse]
- uapi.responses.make_response_adapter(return_type, framework_response_cls, converter, shorthands)#
Potentially create a function to adapt the return type to something uapi understands.
- Parameters:
return_type (Any) –
framework_response_cls (type) –
converter (Converter) –
shorthands (Iterable[type[ResponseShorthand]]) –
- Return type:
Callable[[Any], BaseResponse] | None
uapi.shorthands module#
- class uapi.shorthands.BytesShorthand(*args, **kwargs)#
Bases:
ResponseShorthand
[bytes
]Support for handlers returning bytes.
The response code is set to 200 and the content type is set to application/octet-stream.
- static is_union_member(value)#
Return whether the actual value of a union is this type.
Used when handlers return unions of types.
- Parameters:
value (Any) –
- Return type:
bool
- static make_openapi_response(_, builder)#
Produce an OpenAPI response for this shorthand type.
If this isn’t overriden, no OpenAPI schema will be generated.
- Parameters:
_ (Any) –
builder (SchemaBuilder) –
- Return type:
- static response_adapter_factory(type)#
Produce a converter that turns a value of this type into a base response.
- Parameters:
type (Any) – The actual type being handled by the shorthand.
- Return type:
Callable[[Any], BaseResponse]
- class uapi.shorthands.NoneShorthand(*args, **kwargs)#
Bases:
ResponseShorthand
[None
]Support for handlers returning None.
The response code is set to 204, and the content type is left unset.
- static can_handle(type)#
Whether the shorthand can handle this type.
Skip overriding to use an isinstance check and an equality check against the generic type parameter of the shorthand.
- Parameters:
type (Any) –
- Return type:
bool | Literal[‘check_type’]
- static is_union_member(value)#
Return whether the actual value of a union is this type.
Used when handlers return unions of types.
- Parameters:
value (Any) –
- Return type:
bool
- static make_openapi_response(_, __)#
Produce an OpenAPI response for this shorthand type.
If this isn’t overriden, no OpenAPI schema will be generated.
- Parameters:
_ (Any) –
__ (SchemaBuilder) –
- Return type:
- static response_adapter_factory(_)#
Produce a converter that turns a value of this type into a base response.
- Parameters:
type – The actual type being handled by the shorthand.
_ (Any) –
- Return type:
Callable[[Any], BaseResponse]
- uapi.shorthands.ResponseAdapter#
alias of
Callable
[Any
,BaseResponse
]
- class uapi.shorthands.ResponseShorthand(*args, **kwargs)#
Bases:
Protocol
[T_co
]The base protocol for response shorthands.
- static can_handle(type)#
Whether the shorthand can handle this type.
Skip overriding to use an isinstance check and an equality check against the generic type parameter of the shorthand.
- Parameters:
type (Any) –
- Return type:
bool | Literal[‘check_type’]
- static is_union_member(value)#
Return whether the actual value of a union is this type.
Used when handlers return unions of types.
- Parameters:
value (Any) –
- Return type:
bool
- static make_openapi_response(type, builder)#
Produce an OpenAPI response for this shorthand type.
If this isn’t overriden, no OpenAPI schema will be generated.
- Parameters:
type (Any) –
builder (SchemaBuilder) –
- Return type:
Response | None
- static response_adapter_factory(type)#
Produce a converter that turns a value of this type into a base response.
- Parameters:
type (Any) – The actual type being handled by the shorthand.
- Return type:
Callable[[Any], BaseResponse]
- class uapi.shorthands.StrShorthand(*args, **kwargs)#
Bases:
ResponseShorthand
[str
]Support for handlers returning str.
The response code is set to 200 and the content type is set to text/plain.
- static is_union_member(value)#
Return whether the actual value of a union is this type.
Used when handlers return unions of types.
- Parameters:
value (Any) –
- Return type:
bool
- static make_openapi_response(_, builder)#
Produce an OpenAPI response for this shorthand type.
If this isn’t overriden, no OpenAPI schema will be generated.
- Parameters:
_ (Any) –
builder (SchemaBuilder) –
- Return type:
- static response_adapter_factory(type)#
Produce a converter that turns a value of this type into a base response.
- Parameters:
type (Any) – The actual type being handled by the shorthand.
- Return type:
Callable[[Any], BaseResponse]
uapi.starlette module#
- class uapi.starlette.StarletteApp(converter=_Nothing.NOTHING, incant=_Nothing.NOTHING, route_map=_Nothing.NOTHING, openapi_security=_Nothing.NOTHING, framework_incant=_Nothing.NOTHING)#
Bases:
Generic
[C_contra
],AsyncApp
[Union
[C_contra
,Response
]]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) –
- add_response_shorthand(shorthand)#
Add a response shorthand to the App.
Response shorthands enable additional return types for handlers.
The type will be matched by identity and an is_subclass check.
- Parameters:
type – The type to add to possible handler return annotations.
response_adapter – A callable, used to convert a value of the new type into a BaseResponse.
shorthand (type[ResponseShorthand[T_co]]) –
- Return type:
StarletteApp[T_co | C_contra]
- framework_incant: Incanter#
- async run(host='127.0.0.1', port=8000, handle_signals=True, log_level=None)#
Start serving this app using uvicorn.
Cancel the task running this to shut down uvicorn.
- Parameters:
host (str) –
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
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#