- Python Microservices Development
- Tarek Ziadé
- 581字
- 2021-07-02 18:54:20
Discovering Flask
Flask was started around 2010, leveraging the Werkzeug WSGI toolkit (http://werkzeug.pocoo.org/), which provides the foundations for interacting with HTTP requests via the WSGI protocol, and various tools such as a routing system.
Werkzeug is equivalent to Paste, which provided similar features. The Pylons project (http://pylonsproject.org), which is the umbrella organization for projects like Pyramid --another web framework-- integrated Paste and its various components at some point.
Together with Bottle (http://bottlepy.org/) and a handful of other projects, they composed the Python microframeworks ecosystem.
All those projects have a similar goal--they want to offer to the Python community simple tools to build web applications faster.
However, the term microframework can be a bit misleading. It does not mean you can only create micro applications. Using those tools, you can build any application--even a large one. The prefix micro here means that the framework tries to take as few decisions as possible. It lets you freely organize your application code as you want, and use whatever libraries you want.
A typical example of this philosophy is when you need to interact with an SQL database. A framework like Django is batteries-included, and provides everything you need to build your web app including an Object-Relational Mapper (ORM) to bind objects with database query results. The rest of the framework tightly integrates with the ORM.
If you want to use an alternative ORM like SQLAlchemy (SA) in Django to benefit from some of its great features, you'd not be taking the easiest path, because the whole idea of Django is to provide an entire working system, and let the developer focus on building original features.
Flask, on the other hand, does not care what library you use to interact with your data. The framework will only try to make sure it has enough hooks to be extended by external libraries to provide all kinds of features. In other words, using SQLAlchemy in Flask, and making sure you're doing the right thing with SQL sessions and transactions, will mostly consist of adding a package like Flask-SQLAlchemy in your project. And if you don't like how that particular library integrates SLQAlchemy, you're free to use another one, or to build your integration.
Of course, that's not a silver bullet. Being completely free in your choices also means it's easier to make poor decisions, and build an application that relies on defective libraries or one that's not well designed.
But fear not! This chapter will make sure you know what Flask has to offer, and how to organize your code for building microservices.
This chapter covers the following topics:
- Which Python?
- How Flask handles requests
- Flask built-in features
- A microservice skeleton
- Advanced Splunk
- SQL for Data Analytics
- Mastering matplotlib
- Linux環境編程:從應用到內核
- Magento 1.8 Development Cookbook
- Visual C++數字圖像處理技術詳解
- C語言程序設計學習指導與習題解答
- 從0到1:Python數據分析
- 微信小程序開發與實戰(微課版)
- Spring MVC+MyBatis開發從入門到項目實踐(超值版)
- Extending Unity with Editor Scripting
- 單片機原理及應用技術
- Python預測之美:數據分析與算法實戰(雙色)
- AngularJS UI Development
- Java語言程序設計實用教程(第2版)