flask_jsonrpc.types package

Submodules

flask_jsonrpc.types.methods module

class BaseMethodAnnotatedOrigin[source]

Bases: object

class BaseMethodAnnotatedMetadata[source]

Bases: object

class Summary(summary: 'str')[source]

Bases: BaseMethodAnnotatedMetadata

Parameters:

summary (str)

summary: str
class Description(description: 'str')[source]

Bases: BaseMethodAnnotatedMetadata

Parameters:

description (str)

description: str
class Validate(validate: 'bool' = True)[source]

Bases: BaseMethodAnnotatedMetadata

Parameters:

validate (bool)

validate: bool
class Notification(notification: 'bool' = True)[source]

Bases: BaseMethodAnnotatedMetadata

Parameters:

notification (bool)

notification: bool
class Deprecated(deprecated: 'bool' = True)[source]

Bases: BaseMethodAnnotatedMetadata

Parameters:

deprecated (bool)

deprecated: bool
class Tag(name: 'str', summary: 'str | None' = None, description: 'str | None' = None)[source]

Bases: BaseMethodAnnotatedMetadata

Parameters:
  • name (str)

  • summary (str | None)

  • description (str | None)

name: str
summary: str | None
description: str | None
class Error(code: 'int', message: 'str', status_code: 'int' = 500, data: 't.Any | None' = None)[source]

Bases: BaseMethodAnnotatedMetadata

Parameters:
  • code (int)

  • message (str)

  • status_code (int)

  • data (Any | None)

code: int
message: str
status_code: int
data: Any | None
class ExampleField(name: 'str', value: 't.Any', summary: 'str | None' = None, description: 'str | None' = None)[source]

Bases: BaseMethodAnnotatedMetadata

Parameters:
  • name (str)

  • value (Any)

  • summary (str | None)

  • description (str | None)

name: str
value: Any
summary: str | None
description: str | None
class Example(name: 'str', summary: 'str | None' = None, description: 'str | None' = None, params: 'list[ExampleField] | None' = None, returns: 'ExampleField | None' = None)[source]

Bases: BaseMethodAnnotatedMetadata

Parameters:
name: str
summary: str | None
description: str | None
params: list[ExampleField] | None
returns: ExampleField | None
MethodAnnotatedType

alias of _MethodAnnotatedAlias

flask_jsonrpc.types.params module

extract_digits_and_decimals(value)[source]
Parameters:

value (Decimal)

Return type:

tuple[int, int]

class Ok(value)[source]

Bases: object

A successful type check result.

Parameters:

value (Any)

value: Any
class Err(message)[source]

Bases: object

An unsuccessful type check result.

Parameters:

message (str)

message: str
class BaseAnnotatedMetadata[source]

Bases: object

Base class for annotated metadata used in type checking.

type_check(name, value)[source]
Parameters:
Return type:

Ok | Err

class DefaultTypeCheckMixin[source]

Bases: object

Mixin class that provides a default type check implementation.

type_check(name, value)[source]

Perform a default type check that always succeeds.

Parameters:
Return type:

Ok | Err

class Summary(summary: 'str')[source]

Bases: DefaultTypeCheckMixin, BaseAnnotatedMetadata

Parameters:

summary (str)

summary: str
class Description(description: 'str')[source]

Bases: DefaultTypeCheckMixin, BaseAnnotatedMetadata

Parameters:

description (str)

description: str
class Properties(annotations: 'dict[str, t.Annotated[t.Any, ...] | t.Any]')[source]

Bases: DefaultTypeCheckMixin, BaseAnnotatedMetadata

Parameters:

annotations (dict[str, Annotated[Any, Ellipsis] | Any])

annotations: dict[str, Annotated[Any, Ellipsis] | Any]
class Example(name: 'str', value: 't.Any')[source]

Bases: DefaultTypeCheckMixin, BaseAnnotatedMetadata

Parameters:
name: str
value: Any
class Required(required: 'bool' = True)[source]

Bases: BaseAnnotatedMetadata

Parameters:

required (bool)

required: bool
type_check(name, value)[source]
Parameters:
Return type:

Ok | Err

class Deprecated(deprecated: 'bool' = True)[source]

Bases: DefaultTypeCheckMixin, BaseAnnotatedMetadata

Parameters:

deprecated (bool)

deprecated: bool
class Nullable(nullable: 'bool' = True)[source]

Bases: BaseAnnotatedMetadata

Parameters:

nullable (bool)

nullable: bool
type_check(name, value)[source]
Parameters:
Return type:

Ok | Err

class Maximum(maximum: 't.Annotated[float, annotated_types.Ge(0)]')[source]

Bases: BaseAnnotatedMetadata

Parameters:

maximum (Annotated[float, Ge(ge=0)])

maximum: Annotated[float, Ge(ge=0)]
type_check(name, value)[source]
Parameters:
Return type:

Ok | Err

class Minimum(minimum: 't.Annotated[float, annotated_types.Ge(0)]')[source]

Bases: BaseAnnotatedMetadata

Parameters:

minimum (Annotated[float, Ge(ge=0)])

minimum: Annotated[float, Ge(ge=0)]
type_check(name, value)[source]
Parameters:
Return type:

Ok | Err

class MultipleOf(multiple_of: 't.Annotated[float, annotated_types.MultipleOf(0)]')[source]

Bases: BaseAnnotatedMetadata

Parameters:

multiple_of (Annotated[float, MultipleOf(multiple_of=0)])

multiple_of: Annotated[float, MultipleOf(multiple_of=0)]
type_check(name, value)[source]
Parameters:
Return type:

Ok | Err

class MaxLength(max_length: 't.Annotated[int, annotated_types.Ge(0)]')[source]

Bases: BaseAnnotatedMetadata

Parameters:

max_length (Annotated[int, Ge(ge=0)])

max_length: Annotated[int, Ge(ge=0)]
type_check(name, value)[source]
Parameters:
Return type:

Ok | Err

class MinLength(min_length: 't.Annotated[int, annotated_types.Ge(0)]')[source]

Bases: BaseAnnotatedMetadata

Parameters:

min_length (Annotated[int, Ge(ge=0)])

min_length: Annotated[int, Ge(ge=0)]
type_check(name, value)[source]
Parameters:
Return type:

Ok | Err

class Pattern(pattern: 't.Pattern[str] | str')[source]

Bases: BaseAnnotatedMetadata

Parameters:

pattern (Pattern[str] | str)

pattern: Pattern[str] | str
type_check(name, value)[source]
Parameters:
Return type:

Ok | Err

class AllowInfNan(allow_inf_nan: 'bool' = True)[source]

Bases: BaseAnnotatedMetadata

Parameters:

allow_inf_nan (bool)

allow_inf_nan: bool
type_check(name, value)[source]
Parameters:
Return type:

Ok | Err

class MaxDigits(max_digits: 't.Annotated[int, annotated_types.Ge(0)]')[source]

Bases: BaseAnnotatedMetadata

Parameters:

max_digits (Annotated[int, Ge(ge=0)])

max_digits: Annotated[int, Ge(ge=0)]
type_check(name, value)[source]
Parameters:
Return type:

Ok | Err

class DecimalPlaces(decimal_places: 't.Annotated[int, annotated_types.Ge(0)]')[source]

Bases: BaseAnnotatedMetadata

Parameters:

decimal_places (Annotated[int, Ge(ge=0)])

decimal_places: Annotated[int, Ge(ge=0)]
type_check(name, value)[source]
Parameters:
Return type:

Ok | Err

flask_jsonrpc.types.types module

class AnnotatedMetadataAutoGenerated(auto_generated: 'bool' = True)[source]

Bases: object

Parameters:

auto_generated (bool)

auto_generated: bool
exception AnnotatedMetadataTypeError(annotated, name, value, message)[source]

Bases: TypeError

Parameters:
Return type:

None

type_checker(view_func, params)[source]

Check the types of parameters for a given view function based on its annotations.

Parameters:
  • view_func (Callable[..., Any]) – The view function to check.

  • params (dict[str, Any]) – The parameters to check.

Returns:

The checked parameters.

Return type:

dict[str, Any]

type_metadata_checker(metadata, name, value)[source]

Check the metadata constraints for a given parameter.

Parameters:
  • metadata (tuple[Any, ...]) – The metadata to check.

  • name (str) – The name of the parameter.

  • value (Any) – The value of the parameter.

Returns:

The checked value.

Return type:

Any

Raises:

AnnotatedMetadataTypeError – If the value does not satisfy the metadata constraints.

to_dict(obj, *, level=0, max_level=5)[source]

Convert a type annotation to a dictionary representation.

If the maximum recursion level is reached, the type annotation is wrapped in an Annotated type with AnnotatedMetadataAutoGenerated.

Parameters:
  • obj (Any) – The type annotation to convert.

  • level (int) – The current recursion level.

  • max_level (int) – The maximum recursion level.

Returns:

The dictionary representation of the type annotation.

Return type:

Any

Examples

>>> to_dict(list[int])
[typing.Annotated[int, AnnotatedMetadataAutoGenerated(auto_generated=True)]]
>>> to_dict(dict[str, float])
typing.Annotated[dict[str, float], AnnotatedMetadataAutoGenerated(auto_generated=True)]
propertify(obj, *, level=0, max_level=5)[source]

Convert a type annotation to a Properties representation.

Parameters:
  • obj (Any) – The type annotation to convert.

  • level (int) – The current recursion level.

  • max_level (int) – The maximum recursion level.

Returns:

The Properties representation of the type annotation.

Return type:

Any

See also

flask_jsonrpc.types.to_dict(): Convert a type annotation to a dictionary representation.

class JSONRPCNewType(name, *types)[source]

Bases: object

A new type for JSON-RPC type checking and representation.

Parameters:
  • name (str) – The name of the new type.

  • types (type | tuple[type | tuple[type, ...], ...]) – The types that this new type represents.

name

The name of the new type.

Type:

str

types

The types that this new type represents.

Type:

tuple[type | tuple[type, …], …]

Examples

>>> String = JSONRPCNewType('String', str, bytes)
>>> String.check_type(str)
True
>>> String.check_type(int)
False
check_type(o)[source]

Check if the given type matches this new type.

Parameters:
  • o (Any) – The type to check.

  • self (Self)

Returns:

True if the given type matches this new type, False otherwise.

Return type:

bool

Examples

>>> String = JSONRPCNewType('String', str, bytes)
>>> String.check_type(str)
True
>>> String.check_type(int)
False

Module contents