Skip to main content

No project description provided

Project description

Falibrary

GitHub Actions GitHub PyPI - Python Version

Falcon add-on for API specification and validation.

Provide OpenAPI document and validation for flask service.

Mainly built for Machine Learning Model services.

If you're using Flask, check my another Python library Flaskerk.

Quick Start

Install with pip install falibrary (Python 3.6+)

import falcon
from wsgiref import simple_server
from pydantic import BaseModel, Schema
from random import random

from falibrary import Falibrary

api = Falibrary(
    title='Demo Service',
    version='0.1.2',
)

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

class Classification():
    @api.validate(query=Query, data=Data, resp=Response, x=[falcon.HTTP_403])
    def on_post(self, req, resp, source, target):
        print(f'{source} => {target}')
        print(req.context.query)
        print(req.context.data)
        if random() < 0.5:
            raise falcon.HTTPForbidden("Bad luck. You're fobidden.")
        return Response(label=int(10 * random()), score=random())

if __name__ == '__main__':
    app = falcon.API()
    app.add_route('/api/{source}/{target}', Classification())
    api.register(app)

    httpd = simple_server.make_server('localhost', 8000, app)
    httpd.serve_forever()

Try it with http POST ':8000/api/zh/en?text=hello' uid=0b01001001 limit=5 vip=true.

Open the docs in http://127.0.0.1:8000/apidoc .

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

falibrary-0.3.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

falibrary-0.3.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file falibrary-0.3.0.tar.gz.

File metadata

  • Download URL: falibrary-0.3.0.tar.gz
  • Upload date:
  • Size: 6.3 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 falibrary-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b619ac36642813edf3a4d2d647bc3ec87f1f107099f19f0d958c8f78dcebad06
MD5 571bdf452a11064a2938b5893efb4dde
BLAKE2b-256 2701ee38395c0f338508911fe10d796997f739bee6740858803d23600217404a

See more details on using hashes here.

File details

Details for the file falibrary-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: falibrary-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 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 falibrary-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00058b2000a84490c5cb736a6fcf5fa05abf8eb44d37718e4cc67c82b171b03c
MD5 67c9d6cb0c652d81ef1f4bb662326c55
BLAKE2b-256 9fe78eeba88cd9ba27c06e877d685aa9be4b7ec44b89db8b265796b02b655a8e

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