O'Reilly logo

Flask Blueprints by Joël Perras

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Simple APIs with Flask-RESTful

One of the great joys of using Flask is the seemingly infinite extensibility and composability that it offers. As it's a rather thin layer that sits atop Werkzeug and Jinja, it does not impose much on the developer in terms of constraints.

Due to this flexibility, we have extensions such as Flask-RESTful at our disposal, which make creating JSON-based APIs a joy. First, let's install the package:

$ pip install flask-restful

Next, let's initialize the extension in our application factory in the usual fashion:

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.bcrypt import Bcrypt
from flask.ext.restful import Api

# ………
api = Api() def create_app(config=None): app = Flask(__name__) if ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required