Skip to main content

flask api toolset

Project description

flask-api-spec

PyPI version

flask API toolset

pip install flask-api-spec

started with a simple idea

Let's

  • write validation codes for requests
  • write validation and serialization codes for responses
  • write API body
  • integrate authorizations then protect the APIs
  • swaggerize all of them automatically
  • with Flask

usage

installation

import flask_api_spec

app = Flask(__name__)
flask_api_spec.init_app(app)

examples

from flask_api_spec import Value


@app.route('/hello', apispec=dict(
    query=dict(  # constraints for request.args
        id=Value(int, error='There is not id or id is not int.')
    )
))
def hello_id():
    return dict(result='The id is %s' % request.args['id'])

Focus on what begins with apispec=. We've got a robust feature for the API using the extended app.route with the apispec keyword argument.

from flask_api_spec import Value


@app.route('/hello/<string:name>', apispec=dict(
    param=dict(  # constraints for parameters
        name=Value(str, lambda x: len(x) > 3, error='name is no string or the length is not greater than 3')
    )
))
def hello_name(name):
    return dict(result='Hello %s!' % name)

A param keyword in apispec= indicates in-path parameters. We can state some more detailed rules about them explicitly. In the case above, size of <string:name> should exceed 3.

todo

  • support more mashmallow functionalities
  • support more schema functionalities
  • integrate authorization
  • generate full swagger yaml
  • support flask class view

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

flask-api-spec-0.1.10.tar.gz (410.6 kB view details)

Uploaded Source

File details

Details for the file flask-api-spec-0.1.10.tar.gz.

File metadata

  • Download URL: flask-api-spec-0.1.10.tar.gz
  • Upload date:
  • Size: 410.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.5

File hashes

Hashes for flask-api-spec-0.1.10.tar.gz
Algorithm Hash digest
SHA256 e77ae18e0a4f441968cb83e80678b66b56fd1595b954141c9dd447eb0f74b5c2
MD5 dc8d960ef4d22bd2641c8f813e76252b
BLAKE2b-256 3e0bde07812575aef978d9029feae62b5db4b182554481787cfcef1f3f762082

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