Python Microservices Development
eBook - ePub

Python Microservices Development

Build efficient and lightweight microservices using the Python tooling ecosystem, 2nd Edition

Simon Fraser, Tarek Ziadé

Buch teilen
  1. 310 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Python Microservices Development

Build efficient and lightweight microservices using the Python tooling ecosystem, 2nd Edition

Simon Fraser, Tarek Ziadé

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Use Python microservices to craft applications that are built as small standard units using proven best practices and avoiding common errors

Key Features

  • Become well versed with the fundamentals of building, designing, testing, and deploying Python microservices
  • Identify where a monolithic application can be split, how to secure it, and how to scale it once ready for deployment
  • Use the latest framework based on asynchronous programming to write effective microservices with Python

Book Description

The small scope and self-contained nature of microservices make them faster, cleaner, and more scalable than code-heavy monolithic applications. However, building microservices architecture that is efficient as well as lightweight into your applications can be challenging due to the complexity of all the interacting pieces.

Python Microservices Development, Second Edition will teach you how to overcome these issues and craft applications that are built as small standard units using proven best practices and avoiding common pitfalls. Through hands-on examples, this book will help you to build efficient microservices using Quart, SQLAlchemy, and other modern Python tools

In this updated edition, you will learn how to secure connections between services and how to script Nginx using Lua to build web application firewall features such as rate limiting. Python Microservices Development, Second Edition describes how to use containers and AWS to deploy your services. By the end of the book, you'll have created a complete Python application based on microservices.

What you will learn

  • Explore what microservices are and how to design them
  • Configure and package your code according to modern best practices
  • Identify a component of a larger service that can be turned into a microservice
  • Handle more incoming requests, more effectively
  • Protect your application with a proxy or firewall
  • Use Kubernetes and containers to deploy a microservice
  • Make changes to an API provided by a microservice safely and keep things working
  • Identify the factors to look for to get started with an unfamiliar cloud provider

Who this book is for

This book is for developers who want to learn how to build, test, scale, and manage Python microservices. Readers will require basic knowledge of the Python programming language, the command line, and HTTP-based application principles. No prior experience of writing microservices in Python is assumed.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Python Microservices Development als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Python Microservices Development von Simon Fraser, Tarek Ziadé im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Web Programming. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2021
ISBN
9781801079372

2

Discovering Quart

Quart was started in 2017 as an evolution of the popular Flask framework. Quart shares many of the same design decisions as Flask, and so a lot of the advice for one will work with the other. This book will focus on Quart to allow us to support asynchronous operations and to explore features such as WebSockets and HTTP/2 support.
Quart and Flask are not the only Python frameworks. There is a long history of projects aimed at providing services on the web, such as Bottle, cherrypy, and Django. All of these tools are used around the web, and they all share a similar goal: to offer the Python community simple tools for building web applications quickly.
The smaller frameworks, such as Quart and Bottle, are often called microframeworks; however, the term can be a bit misleading. It does not mean you can only create micro-applications. Using those tools, you can build any application, large or small. The prefix "micro" means that the framework tries to make as few decisions as possible. It lets you freely organize your application code and use whichever libraries you want.
A microframework acts as the glue code that delivers requests to your system and sends back responses. It does not enforce any particular paradigm on your project.
A typical example of this philosophy is when you need to interact with a SQL database. A framework such as 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.
If you want to use an alternative ORM such as SQLAlchemy in Django to benefit from some of its great features, you'd be choosing a difficult path that would involve rewriting a lot of the Django library you are hoping to make use of, because of the tight integration Django has with the ORM it comes with. For certain applications, that's a good thing, but not necessarily for producing a microservice.
Quart, on the other hand, does not have a built-in library to interact with your data, leaving you free to choose your own. The framework will only attempt to make sure it has enough hooks to be extended by external libraries to provide various kinds of features. In other words, using an ORM in Quart, and making sure you're doing the right thing with SQL sessions and transactions, will mostly consist of adding a package such as SQLAlchemy to your project. If you don't like how a particular library integrates, you're free to use another one or to build your own integration. Quart can also make use of the more common Flask extensions, although there is a performance risk there as they are unlikely to be asynchronous and could block your application's work.
Of course, that's not a silver bullet. Being completely free in your choices also means that it is easier to make poor decisions and build an application that relies on defective libraries, or one that is not well designed. But fear not! This chapter will make sure you know what Quart has to offer, and how to organize your code for building microservices.
This chapter covers the following topics:
  • Making sure we have Python
  • How Quart handles requests
  • Quart's built-in features
  • A microservice skeleton
The goal of this chapter is to give you all the information needed to build microservices with Quart. By doing so, it inevitably duplicates some of the information you can find in Quart's official documentation, but focuses on providing interesting details and anything relevant when building microservices. Quart and Flask have good online documentation.
Make sure you take a look at Quart's and Flask's documentation, listed respectively:
  • https://pgjones.gitlab.io/quart/index.html
  • https://flask.palletsprojects.com/
Both should serve as a great complement to this chapter. The source code is located at https://gitlab.com/pgjones/quart.
This is worth being aware of, as the source code is always the ultimate truth when you need to understand how the software works.

Making sure we have Python

Before we start digging into its features, we should make sure that we have Python installed and working!
You might see some documentation or posts online that mention Python version 2. There was a long transition from Python 2 to Python 3, and had this book been written a few years earlier, we would be discussing the merits of each. However, Python 3 is fully capable of everything the majority of people need to do, and Python 2 stopped being supported by the core Python team in 2020. This book uses the latest Python 3.9 stable release for all its code examples, but they are likely to work on Python 3.7 or later, as that's the minimum version that Quart requires in order to work.
If your computer does not have at least Python 3.7, you can download a new version from Python's own website, where installation instructions are provided: https://www.python.org/downloads/.
You will find it easier if all the code examples in this book are run in a virtual environment, or virtualenv (https://docs.python.org/3/library/venv.html). A virtual environment is Python's way of keeping each project separate, as it means you can install Quart and any other libraries you need; it will only affect the application you are currently working on. Other applications and projects can have different libraries, or different versions of the same library, without them getting in the way of each other. Using a virtualenv also means that you can easily recreate your project's dependencies somewhere else, which will be very useful when we deploy a microservice in a later chapter.
Some code editors, such as PyCharm or Visual Stu...

Inhaltsverzeichnis