Flask, Flask RESTful and RESTPlus Comparison

Sisay A. Chala
3 min readApr 11, 2021

--

This article tries to compare Flask REST, Flask-RESTful and Flask-RESTPlus using minimal Flask app with endpoints for GET and POST.

  1. Flask REST

Flask is a highly flexible Python web framework built with a small core and easy-to-extend philosophy.

Flask-REST minimal code for GET and POST requests
Figure 1. Flask REST minimal code for GET and POST requests

2. Flask RESTFul

Flask-Restful is an extension of Flask that offers extension to enable writing a clean object-oriented code for fast API development. It provides abstractions to work with existing Object Relational Mapping (ORM) and supports other useful libraries. It enables you to write a clean object-oriented code that is highly reusable.

Flask-RESTful minimal code for GET and POST requests
Figure 2. Flask-RESTful minimal code for GET and POST requests

The code in Flask-RESTful (Figure 2) mainly differs from the one in Flask (Figure 1) in that both services in Figure 1 are organized under one class of resource. More specifically, Line 2 imports the requirements for Flask-RESTful (Resource and Api). In Line 6, the Flask app is wrapped under Flask-RESTful’s Api. Line 18 offers the route “/hello” to access the resource “HelloWorld”.

3. Flask RESTPlus

Flask-RESTPlus is yet another extension for Flask that adds support for quickly building REST APIs. Like Flask-Restful, Flask-RESTPlus encourages best practices with minimal setup. It provides a coherent collection of decorators and tools to describe your API. Flask-RESTPlus exposes its documentation properly (using Swagger).

Flask-RESTPlus minimal code for GET and POST requests
Figure 3. Flask-RESTPlus minimal code for GET and POST requests

The code in Flask-RESTPlus (Figure 3) mainly differs from the one in Flask (Figure 1) in that both services in Figure 1 are organized under one class of resource. More specifically, Line 2 imports the requirements for Flask-RESTPlus (Resource and Api). In Line 6, the Flask app is wrapped under Flask-RESTPlus’ Api.

Note that Line 6 and Line 11 of Figure 1 are equivalent to Line 8 of Figure 3 and Line 18 of Figure 2. Note also that Line 2 in Figure 2 and Figure 3 are different!

The nice thing in Flask-RESTPlus is that it provides Swagger documentation. That is, when you browse to the root of the URL, i.e., in this case http://localhost:5000/, you get the swagger documentation shown in Figure 4 below.

Figure 4. Swagger documentation for the API’s in Flask-RESTPlus

I hope the article helped you figure out the difference between these widely used frameworks in API development. For more comparison parameters, see here.

If you have any question or feedback, please let me know in the comment section.

--

--