Skip to main content

A Web API development toolkit for Flask.

Project description

APIFlask

Build status codecov

A lightweight Web API toolkit for Flask, based on marshmallow-code projects and other Flask extensions.

Currently this project is in plan/experimental stage, break changes are expected. Improvement and suggestions are welcome!

Installation

$ pip install apiflask

Example

from apiflask import APIFlask
from apiflask.decorators import arguments, body, response
from marshmallow import Schema

app = APIFlask(__name__)

class PetSchema(Schema):
    id = Integer(dump_only=True)
    name = String(required=True)
    age = Integer(required=True)
    category = String(required=True)


@app.route('/pets/<int:pet_id>')
@response(PetSchema)
def get_pet(pet_id):
    pass


@app.route('/pets', methods=['POST'])
@body(PetSchema)
@response(PetSchema)
def create_pet(pet):
    pass


@app.route('/pets', methods=['PUT'])
@body(PetSchema)
@response(PetSchema)
def update_pet(updated_pet, pet_id):
    pass

Save the file as app.py, then run it with:

$ flask run

Now visit the interactive docs by Swagger UI at http://localhost:5000/docs:

Or you can visit the alternative Redoc docs at http://localhost:5000/redoc:

The auto-generated OpenAPI spec file are available at http://localhost:5000/openapi.json.

Links


APIFlask starts as a fork of APIFairy 0.6.3dev and inspired by FastAPI.

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

APIFlask-0.1.0.tar.gz (6.9 kB view hashes)

Uploaded Source

Built Distribution

APIFlask-0.1.0-py3-none-any.whl (9.7 kB view hashes)

Uploaded Python 3

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