Migrated from Flask-RESTPlus to Flask-RESTX

Conclusion

--Flask-RESTPlus seems to stop maintenance, and if you continue to use it, its fork, Flask-RESTX, looks good. --For existing code, just replacing flask_restplus with flask_restx worked. --The parameter name also needed to be changed to reflect the config settings

Trigger

I was developing a little Web API server in Flask and documented the API specification in Swagger using Flask-RESTPlus. The development on the Flask side has been calm and I haven't touched it for the past month or so, but an error occurred when I tried to check the operation with a slight modification.

When I check the log, it is moss in the werkzeug package. The level is not near the correction point.

../../../../.pyenv/versions/3.6.9/envs/testenv/lib/python3.6/site-packages/flask_restplus/fields.py:17: in <module>
    from werkzeug import cached_property
E   ImportError: cannot import name 'cached_property'

Certainly, in the past month or so, I had deleted the virtualenv at hand for various reasons, and recreated it at the timing of this correction. I've reinserted the package in pip's requirements.txt, but something may be happening due to version dependencies.

Investigation

Cause

If you google, the issue on Github will be a hit. It looks like this. flask-restplus is broken by Werkzeug 1.0.0 #777

Cached_property moved from under werkzeug to under werkzeug.utils when Werkzeug went to version 1.0.0 in early February 2020. Since flask_restplus was used by importing cached_property, it seems that the above error occurred. Flask's package dependencies are written as Werkzeug> = 0.15, so installing pip modules from scratch will be affected by a major version upgrade of Werkzeug.

Get to know Flask-RESTX

Looking at the README.md of Flask-RESTPlus Github page again, the following description is at the beginning. It was added around the beginning of January 2020.

IMPORTANT NOTICE:

This project has been forked to Flask-RESTX <https://github.com/python-restx/flask-restx>_ and will be maintained by by the python-restx <https://github.com/python-restx>_ organization. Flask-RESTPlus should be considered unmaintained.

Flask-RESTPlus will no longer be maintained, the fork Flask-RESTX will be maintained in the future. And that.

Using Flask-RESTX

Try using

It would be nice to manually lower the version of Werkzeug, but I thought that development would continue for a while, so I decided to try Flask-RESTX. As far as the Flask-RESTX page is concerned, the usage is almost the same as Flask-RESTPlus, and it looks good. So I tried to move it by simple replacement for the time being. The code looks like this.

flask_restplus


from flask_restplus import Namespace, fields, Resource
from flask_restplus.namespace import HTTPStatus

flask_restx


from flask_restx import Namespace, fields, Resource
from flask_restx.namespace import HTTPStatus

With this alone, it came to work without outputting an error for the time being. Flask-RESTX uses the latest version of PyPI, 0.1.1. It has a limitation of werkzeug (<= 0.16.1), so it seems that the problem will be solved by reinstalling the pip package.

After checking the latest code on Github, it seems that werkzeug 1.0.0 is okay with the import writing method modified. I hope PyPI will reflect this version in the future.

A little more detailed confirmation

I changed the setting in config to the default or a little, but this also did not reflect the setting unless I changed the key name of dict. This also just changes RESTPLUS_ to RESTX_, so it's helpful to be mechanical.

flask_restplus


app.config['RESTPLUS_MASK_SWAGGER'] = False
app.config['RESTPLUS_JSON'] = {'ensure_ascii': False}

flask_restx


app.config['RESTX_MASK_SWAGGER'] = False
app.config['RESTX_JSON'] = {'ensure_ascii': False}

Recommended Posts

Migrated from Flask-RESTPlus to Flask-RESTX
Sum from 1 to 10
Changes from Python 2 to Python 3.0
From editing to execution
Cheating from PHP to Python
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Update python-social-auth from 0.1.x to 0.2.x
Migrate from requirements.txt to pipenv
Switch from python2.7 to python3.6 (centos7)
Connect to sqlite from python
Call Matlab from Python to optimize
From Elasticsearch installation to data entry
vtkXMLUnstructuredGridReader Summary (updated from time to time)
vtkOpenFOAMReader Summary (Updated from time to time)
How to use SWIG from waf
Cannot migrate from direct_to_template to TemplateView
Engineer vocabulary (updated from time to time)
Create folders from '01' to '12' with python
Conversion from pdf to txt 1 [pdfminer]
Programming to learn from books May 10
Post from python to facebook timeline
[Lambda] [Python] Post to Twitter from Lambda!
Output from Raspberry Pi to Line
[Introduction] From installing kibana to starting
Convert from pdf to txt 2 [pyocr]
Connect to utf8mb4 database from python
OpenMPI installation from download to pass-through
Tensorflow memo [updated from time to time]
Python (from first time to execution)
Post images from Python to Tumblr
Send commands from Atom to Maya
How to launch Explorer from WSL
Programming to learn from books May 7
From Ubuntu 20.04 introduction to environment construction
Ssh connect to GCP from Windows
How to access wikipedia from python
Python to switch from another language
How to convert from .mgz to .nii.gz
Migrate from VS Code to PyCharm
pynq-z1 From purchase to operation check
Review from git init to git push
Did not change from Python 2 to 3
Update Python on Mac from 2 to 3