Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Microservices Development – 2nd edition

You're reading from   Python Microservices Development – 2nd edition Build efficient and lightweight microservices using the Python tooling ecosystem

Arrow left icon
Product type Paperback
Published in Sep 2021
Publisher Packt
ISBN-13 9781801076302
Length 310 pages
Edition 2nd Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Tarek Ziadé Tarek Ziadé
Author Profile Icon Tarek Ziadé
Tarek Ziadé
Simon Fraser Simon Fraser
Author Profile Icon Simon Fraser
Simon Fraser
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Understanding Microservices 2. Discovering Quart FREE CHAPTER 3. Coding, Testing, and Documentation: the Virtuous Cycle 4. Designing Jeeves 5. Splitting the Monolith 6. Interacting with Other Services 7. Securing Your Services 8. Making a Dashboard 9. Packaging and Running Python 10. Deploying on AWS 11. What's Next? 12. Other Books You May Enjoy
13. Index

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 Studio, may manage a virtual environment for you. Every code example in the book runs in a terminal, and so we will use a terminal to create our virtualenv. This also shows how things work in more detail than viewing a program's output on the web, or in log files, and will be helpful when fixing any problems in the future.

In a terminal, such as a macOS Terminal application, or a Windows Subsystem for Linux, change to the directory you would like to work in and run the following command:

python -m venv my-venv

Depending on how you installed Python, you may need to use python3 to create the virtual environment.

This creates a new virtual environment called my-venv in the current directory. You could give it another path if you like, but it's important to remember where it is. To use the virtual environment, you must activate it:

source my-venv/bin/activate

For most of the command-line examples in this book, we assume you are running on Linux, as that is what most services online use, so it is good to be familiar with it. This means that most of the commands will also work on macOS or on Windows using the Windows Subsystem for Linux. It's also possible to run Docker containers on all these systems, and we will describe containers later on when we discuss deploying your microservice.

Now, let's install Quart so that we can run our example code:

pip install quart

To stop using the virtual environment without closing the terminal, you can type deactivate. For now, though, let's keep the virtualenv active and look at how Quart will work.

You have been reading a chapter from
Python Microservices Development – 2nd edition - Second Edition
Published in: Sep 2021
Publisher: Packt
ISBN-13: 9781801076302
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image