Flask-RESTAPI is an extension for validate and make OpenAPI docs.
Project description
Flask-RESTAPI
Flask-RESTAPI is an extension for Flask that is a database-agnostic framework library for creating REST APIs. It is a lightweight abstraction that works with your existing ORM/libraries.
It use pydantic to validate and serialize data. OpenAPI document can be automatically generated through the python decorator and it supports swagger ui display.
Pydantic are used to validate and serialize parameters. For details, please refer to the pydantic documentation.
Installation
pip install flask-restapi
Example
from flask import Flask
from flask.views import MethodView
from pydantic import BaseModel
from flask_restapi import Api, RequestParametersType
app = Flask(__name__)
api = Api(app)
class UserGetSpec(BaseModel):
name: str
class UserResponseSpec(BaseModel):
id: int
name: str
class User(MethodView):
@api.query(UserGetSpec)
@api.response(UserResponseSpec)
def get(self, parameters: RequestParametersType):
"""Get a user name and id"""
user_name = parameters.query.name
return UserResponseSpec(id=1, name=user_name)
app.add_url_rule("/user", view_func=User.as_view("user"))
Swagger API docs
Now go to http://localhost:5000/docs
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask-restapi-0.3.1.tar.gz.
File metadata
- Download URL: flask-restapi-0.3.1.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.7.3 Linux/4.19.104-microsoft-standard
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1d6598d0e912c3e416d30ba7e5d2d469ae4df1a683382e8f6b4e06e4db56cae
|
|
| MD5 |
2bbeed45bcf44d5675e74acac6a66505
|
|
| BLAKE2b-256 |
4aa18f081421b06e671c39a93c696fd189b104e7609c418596305747079fa838
|
File details
Details for the file flask_restapi-0.3.1-py3-none-any.whl.
File metadata
- Download URL: flask_restapi-0.3.1-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.7.3 Linux/4.19.104-microsoft-standard
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc483d593eb2f34271f84b72bc0ade4558411be556fbc139822a0e0e4557d7e9
|
|
| MD5 |
3e3a2a431742419c76861b11a5ab5352
|
|
| BLAKE2b-256 |
f80e1553b975e3b869efb0907ec4fb5d749e324f5c5a76f18413c1252bd5217e
|