Opyapi is a python framework build around Open API specification to provide toolset for rapid REST api development.
No bloat. Just code.
- Automated documentation generation
- Routing
- Mock server
- Built-in serialization/deserialization mechanisms
- WSGI compatibility
from opyapi.api import *
from opyapi import TextResponse
@Api(
title="Example rest application",
description="This application greets users",
)
class Application:
pass
@Operation(
"/users/{name}",
method="get",
responses=TextResponse(200),
summary="Says hello with username provided in the route"
)
def hello_user(name: str):
return f"Hello {name}"
Represent boolean values.
from opyapi.schema.types import Boolean
is_hungry = Boolean()
Arguments:
default
assigns default value if none is passed in the requestnullable
accepts nulls, nones as valuedescription
sets open api description for the fielddeprecated
deprecates field in the schemaread_only
sets property to read only mode (POST, PUT, PATCH methods cannot mutate property)write_only
sets property to write only mode (property is hidden from all GET requests)
Represent integer numbers.
from opyapi.schema.types import Integer
age = Integer()
Arguments:
minimum
sets minimum accepted valuemaximum
sets maximum accepted valuemultiple_of
accepts value if it is multiplication of a given numberdefault
assigns default value if none is passed in the requestnullable
accepts nulls, nones as valuedescription
sets open api description for the fielddeprecated
deprecates field in the schemaread_only
sets property to read only mode (POST, PUT, PATCH methods cannot mutate property)write_only
sets property to write only mode (property is hidden from all GET requests)
Represents any valid number, like:
- integer
- rational number
- float
- double
from opyapi.schema.types import Number
money = Number()
Arguments:
minimum
sets minimum accepted valuemaximum
sets maximum accepted valuemultiple_of
accepts value if it is multiplication of a given numberdefault
assigns default value if none is passed in the requestnullable
accepts nulls, nones as valuedescription
sets open api description for the fielddeprecated
deprecates field in the schemaread_only
sets property to read only mode (POST, PUT, PATCH methods cannot mutate property)write_only
sets property to write only mode (property is hidden from all GET requests)
Represent string values.
from opyapi.schema.types import String
email = String(string_format="email")
Arguments:
string_format
sets format for the input, for more details check format listmin_length
sets minimum accepted lengthmax_length
sets maximum accepted lengthpattern
sets regex pattern that value must match, when pattern set format should be omitteddefault
assigns default value if none is passed in the requestnullable
accepts nulls, nones as valuedescription
sets open api description for the fielddeprecated
deprecates field in the schemaread_only
sets property to read only mode (POST, PUT, PATCH methods cannot mutate property)write_only
sets property to write only mode (property is hidden from all GET requests)
Makes string type to accept only ISO8601 valid date time format.
Makes string type to accept only ISO8601 valid date format.
Makes string type to accept only ISO8601 valid time format.
Makes string type to accept only valid email address.
| Please note: that this format can be mean to some special cases of email addresses.
Makes string type to accept only valid email hostname.
Makes string type to accept only valid uri.
Makes string type to accept only valid url, must starts with valid scheme (http/https/ftp).
Makes string type to accept only valid uuid.
Defines enumerated value.
from opyapi.schema.types import Enum
colors = Enum("red", "green", "blue", "yellow")
Arguments:
default
assigns default value if none is passed in the requestnullable
accepts nulls, nones as valuedescription
sets open api description for the fielddeprecated
deprecates field in the schemaread_only
sets property to read only mode (POST, PUT, PATCH methods cannot mutate property)write_only
sets property to write only mode (property is hidden from all GET requests)
Defines iterable/collection item in the schema.
from opyapi.schema.types import Array, Enum
colors = Array(items=Enum("red", "green", "blue", "yellow"))
Arguments:
items
sets valid schema for each item contained in the arraymin_length
sets minimum valid length for the arraymax_length
sets maximum valid length for the arraynullable
accepts nulls, nones as valuedescription
sets open api description for the fielddeprecated
deprecates field in the schemaread_only
sets property to read only mode (POST, PUT, PATCH methods cannot mutate property)write_only
sets property to write only mode (property is hidden from all GET requests)