Flask-API

3.1 · deprecated · verified Thu Apr 16

Flask-API provides tools for building browsable web APIs on top of Flask, offering features like content negotiation and a custom renderer system. While it reached version 3.1, it is now largely unmaintained. Developers starting new projects are strongly advised to use more actively maintained alternatives like Flask-RESTX or Flask-Smorest.

Common errors

Warnings

Install

Imports

Quickstart

A basic Flask-API application demonstrating content negotiation and custom error handling using APIException. When run, it provides a browsable API for the root path and a specific item lookup.

from flask_api import FlaskAPI
from flask_api.exceptions import APIException
from flask_api import status

app = FlaskAPI(__name__)

@app.route('/')
def hello_world():
    return {"message": "Hello, World!"}

@app.route('/items/<int:item_id>/')
def get_item(item_id):
    items = {
        1: {'name': 'Apple', 'price': 1.00},
        2: {'name': 'Banana', 'price': 0.50}
    }
    try:
        return items[item_id]
    except KeyError:
        raise APIException('Item not found', status_code=status.HTTP_404_NOT_FOUND)

if __name__ == '__main__':
    app.run(debug=True)

view raw JSON →