Skip to main content

No project description provided

Project description

Flaskerk

Build Status GitHub PyPI - Python Version

Provide OpenAPI document and validation for flask service.

Mainly built for Machine Learning Model services.

If you're using Falcon, check my another library Falibrary.

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

app = Flask(__name__)
api = Flaskerk()

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__':
    api.register(app)
    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


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.5.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

flaskerk-0.5.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file flaskerk-0.5.1.tar.gz.

File metadata

  • Download URL: flaskerk-0.5.1.tar.gz
  • Upload date:
  • Size: 8.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

Hashes for flaskerk-0.5.1.tar.gz
Algorithm Hash digest
SHA256 f65f02cea460d2e03461b8e3872c5f653753ac3654b23814530b570e7045eb2c
MD5 9ab052dab8667af45d81d88adc979310
BLAKE2b-256 60ca6d5a8aa8eac74d025cbfb21cf61c88264b72cf57dcb220665bd077bee6f9

See more details on using hashes here.

File details

Details for the file flaskerk-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: flaskerk-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 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

Hashes for flaskerk-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 93abda40fdf5b4f7de031acfe3e5119594bc464db8d0cd37fca0e23abdfd6c3e
MD5 fbbee7e6c2f4ef09cedd2c39357a0014
BLAKE2b-256 e79fa8a8799e4c87cf3782e37fc2c873f697294355baf3fd3bba096cbd0cfb5c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page