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
e403 = HTTPException(code=403, msg='lucky for you')
@app.route('/api/predict/<string(length=2):source>/<string(length=2):target>', methods=['POST'])
@api.validate(query=Query, data=Data, resp=Response, x=[e403])
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:
e403.abort()
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.4.tar.gz
(6.8 kB
view details)
Built Distribution
File details
Details for the file flaskerk-0.3.4.tar.gz
.
File metadata
- Download URL: flaskerk-0.3.4.tar.gz
- Upload date:
- Size: 6.8 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 | 6d6bf3704b03dc352c1603586058ac5f3e17384adce5ca678cebbb4241e0c1ca |
|
MD5 | 30703c6b0a2af51bd2f638c6dfee01ae |
|
BLAKE2b-256 | 76f2c9569f2fe00578c0aeed3e866074672c983c0ed8434a5329d33110181dd4 |
File details
Details for the file flaskerk-0.3.4-py3-none-any.whl
.
File metadata
- Download URL: flaskerk-0.3.4-py3-none-any.whl
- Upload date:
- Size: 8.5 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 | 6ef69571761fdd31c7e6f632584623ff4c5c9613cd3ce466b450c9507184026f |
|
MD5 | 94ef5e9f7664d0f93b5a115f311fe8ed |
|
BLAKE2b-256 | d722d3187eceb69bea63ab8f4fbdaf98a88c35c4560517fd1b2cfe75dd3bc93e |