还是选择放弃使用 Eve 作为 RESTful 框架的选择

虽然,Eve 框架很强大,也是基于 Flask,但是我还是选择放弃使用 Eve 了。几点原因:

  1. Eve 内置直接支持的数据库是 Mongo,我们已经不准备在 Mongo 上投入资源了。
  2. Eve 对额外的数据库的支持需要通过 eve-sqlalchemy,来调用 sqlalchemy 和 flask 等,这样就把问题搞的有点复杂化了。等于 flask、sqlalchemy、flask-sqlalchemy、eve、eve-sqllchemy,组合在一起,才能通过 orm 来支持各类数据库。
  3. Eve 的使用还是非常复杂的。
  4. 比较下来 flask-restful 框架就足够了。

flask-restful 框架通过将 class 直接转换为 RESTful 接口:

# Todo
# shows a single todo item and lets you delete a todo item
class Todo(Resource):
    def get(self, todo_id):
        abort_if_todo_doesnt_exist(todo_id)
        return TODOS[todo_id]

    def delete(self, todo_id):
        abort_if_todo_doesnt_exist(todo_id)
        del TODOS[todo_id]
        return '', 204

    def put(self, todo_id):
        args = parser.parse_args()
        task = {'task': args['task']}
        TODOS[todo_id] = task
        return task, 201

用类似下面的方法就直接 ok 了

##
## Actually setup the Api resource routing here
##
api.add_resource(TodoList, '/todos')
api.add_resource(Todo, '/todos/<todo_id>')

对于上面 Todo 这个 class 中数据怎么来,这不是 flask-restful 关心的,我们可以使用 flask-sqlalchemy 来完成这些和数据库操作的真正业务逻辑。

我一直觉得选择 flask 是正确的,它在很多理念的设计上也像微服务框架,每个人做好自己的事情,互相有一个约定来达到协同。

从 git 仓库看,flask-restful 的更新也还不错。

当然用了这个的话,Eve 框架很多强大的比如根据配置文件就能生成接口的能力,就要自己想办法了,初步考虑因为整个这些探索和设计都是为了自动根据数据库来生成 RESTful 接口程序,所以可以使用 DSL 来描述接口要求,将 DSL 转换为基于 flask 体系的 python 程序,来达到这个目的。

Flask, Sanic and Eve, Three Good Web Frameworks For Python

Prepare to improve my English writing ability. I know my English is very stiff, grammar also has many problems. But I still try to persist it. Thanks and sorry for my poor English

In recent years, the performance of Python has been greatly improved. Base on highly asynchronous event processing ability, web framework of Python have been greatly improved. After continued follow-up.  I think the following frameworks are worth future study.

In normal working hours, We use Flask as a web service framework. So I have some preference for flask-like type.

  1. Flask. http://flask.pocoo.org/  We all know, flask has long history and has stable performance. It’s a micro framework and has a lots of extensions. So it’s lightweight and configurable. I believe we will continue to use flask as the mainly web service framework for a long time. The latest version is 0.12.2.
  2. Sanic. https://github.com/channelcat/sanic This is a magical tool, it’s improve the web service performance by using asynchronous technology by Python 3.5+. In practical application, I think flask is enough. Flask can easily do hundreds concurrent in basic server on the cloud. But I believe it, The performance improvement is endless. In particular, the introduction of more and more Micro-Services framework requires that web service framework has strong ability. Sanic web framework much like flask, therefore, the learning and migration costs are relatively low.The latest version is 0.6.0.
  3. Eve. https://github.com/pyeve/eve Eve framework is based on flask, and mainly target is Restful API. As mentioned above, Restful API based design has became the standard in today’s internet application. Eve framework through the configuration file to quickly setup the restful api program. Design of Eve is very smart, we can learn a lots of python programming skill from it.

Currently, based on Flask, I’m studying Sanic and Eve, first, improve program skill of web service. Second, improve my English. At last, python is a profound script language, we will study lots from these famous frameworks, and I will continue share my study notes here. Looking forward to everyone’s correction.