Flask-RESTPlus
raw JSON → 0.13.0 verified Mon Apr 27 auth: no python maintenance
Flask-RESTPlus is a Flask extension for building REST APIs with automatic Swagger documentation. Version 0.13.0 is the final release; the project is effectively in maintenance mode and superseded by Flask-RESTx. It offers request parsing, serialization, and Swagger UI generation.
pip install flask-restplus==0.13.0 Common errors
error No module named 'flask_restplus' ↓
cause Package not installed or misspelled.
fix
Run 'pip install flask-restplus' or use 'flask_restx' for maintained version.
error AttributeError: module 'flask_restplus' has no attribute 'Api' ↓
cause Import from wrong submodule or incorrect package version.
fix
Use 'from flask_restplus import Api' (top-level) and ensure flask-restplus is installed.
error TypeError: Object of type 'Response' is not JSON serializable ↓
cause Returning raw Flask response objects from resource methods.
fix
Return a dictionary or use api.marshal_with instead of manual JSON serialization.
Warnings
breaking Flask-RESTPlus is no longer maintained. The successor is Flask-RESTx, which has breaking API changes (e.g., different decorators for Swagger). ↓
fix Migrate to flask-restx: replace imports from flask_restplus to flask_restx.
deprecated The @api.param decorator is deprecated in later versions; use @api.expect with a parser. ↓
fix Define a RequestParser and use @api.expect(parser).
gotcha Automatic Swagger documentation relies on decorator order. Applying @api.response before @api.route can break docs. ↓
fix Always place @api.response after @api.route and the Resource class definition.
Imports
- Api wrong
from flask_restplus.api import Apicorrectfrom flask_restplus import Api - fields wrong
from flask_restplus.fields import Stringcorrectfrom flask_restplus import fields
Quickstart
from flask import Flask
from flask_restplus import Api, Resource
app = Flask(__name__)
api = Api(app)
@api.route('/hello')
class HelloWorld(Resource):
def get(self):
return {'hello': 'world'}
if __name__ == '__main__':
app.run(debug=True)