No project description provided
Project description
Flaskerk
Provide OpenAPI document and validation for flask service.
Mainly built for Machine Learning Model services.
Features
- JSON data(request&response) validation with pydantic
- support HTTP exceptions (default&customized)
- OpenAPI spec
- Redoc UI
- Swagger UI
- support flask url path validation
- support header validation
- support cookie validation
Quick Start
install with pip install flaskerk
(Python 3.6+)
from flask import Flask, request
from pydantic import BaseModel, Schema
from random import random
from flaskerk import Flaskerk, HTTPException, abort_json
app = Flask(__name__)
api = Flaskerk(app)
class Query(BaseModel):
text: str
class Response(BaseModel):
label: int
score: float = Schema(
...,
gt=0,
lt=1,
)
class Data(BaseModel):
uid: str
limit: int
vip: bool
@app.route('/api/predict/<string(length=2):source>/<string(length=2):target>', methods=['POST'])
@api.validate(query=Query, data=Data, resp=Response, x=[HTTPException(403)])
def predict(source, target):
print(f'=> from {source} to {target}') # path
print(f'Data: {request.json_data}') # Data
print(f'Query: {request.query}') # Query
if random() < 0.5:
abort_json(403)
return Response(label=int(10 * random()), score=random())
if __name__ == '__main__':
app.run()
try it with http POST ':5000/api/predict/zh/en?text=hello' uid=0b01001001 limit=5 vip=true
Open the docs in http://127.0.0.1:5000/docs .
For more examples, check examples.
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
flaskerk-0.3.0.tar.gz
(6.2 kB
view details)
Built Distribution
File details
Details for the file flaskerk-0.3.0.tar.gz
.
File metadata
- Download URL: flaskerk-0.3.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b598e51f570b6e6275cd048e59094027b9548441da8437b9f8e3d2c5ad8e1132 |
|
MD5 | c5bc7f6a498a934875a071e8ed240565 |
|
BLAKE2b-256 | 07e0531b2ef62aa3d738af9f23b7b71d225233c8bdf0b262c260bd5700c685f1 |
File details
Details for the file flaskerk-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: flaskerk-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a269b4a59c4b4289c8c5aec7367e5865e330571014b838be3b64f2573355e9eb |
|
MD5 | ce20d235a32cff466fd9fa2ce6ea6a60 |
|
BLAKE2b-256 | fcda6a79e009678bbd966ed07289d133d92d1d09fe4d4c9014aaf0ee4962e883 |