- 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
- C及C++程序設(shè)計(jì)(第4版)
- 軟件安全技術(shù)
- OpenCV實(shí)例精解
- Linux C/C++服務(wù)器開(kāi)發(fā)實(shí)踐
- JavaScript+jQuery網(wǎng)頁(yè)特效設(shè)計(jì)任務(wù)驅(qū)動(dòng)教程(第2版)
- Java Web開(kāi)發(fā)之道
- Java程序設(shè)計(jì)與計(jì)算思維
- Apache Karaf Cookbook
- Bootstrap 4:Responsive Web Design
- C和C++游戲趣味編程
- Python High Performance Programming
- 寫(xiě)給程序員的Python教程
- 零基礎(chǔ)看圖學(xué)ScratchJr:少兒趣味編程(全彩大字版)
- Visual Basic 程序設(shè)計(jì)實(shí)踐教程
- Android應(yīng)用程序設(shè)計(jì)