Book description
Discover the secrets of building Python microservices using the FastAPI framework
Key Features
- Provides a reference that contains definitions, illustrations, comparative analysis, and the implementation of real-world apps
- Covers concepts, core details, and advanced integration and design-related topics
- Imparts context, app templates, suggestions, and insights that are helpful to actual projects
Book Description
FastAPI is an Asynchronous Server Gateway Interface (ASGI)-based framework that can help build modern, manageable, and fast microservices. Because of its asynchronous core platform, this ASGI-based framework provides the best option when it comes to performance, reliability, and scalability over the WSGI-based Django and Flask. When working with Python, Flask, and Django microservices, you’ll be able to put your knowledge to work with this practical guide to building seamlessly manageable and fast microservices.
You’ll begin by understanding the background of FastAPI and learning how to install, configure, and use FastAPI to decompose business units. You’ll explore a unique and asynchronous REST API framework that can provide a better option when it comes to building microservices. After that, this book will guide you on how to apply and translate microservices design patterns in building various microservices applications and RESTful APIs using the FastAPI framework.
By the end of this microservices book, you’ll be able to understand, build, deploy, test, and experiment with microservices and their components using the FastAPI framework.
What you will learn
- Understand, orient, and implement REST APIs using the basic components of the FastAPI framework
- Build asynchronous as well as synchronous REST services using the built-in pydantic module and asyncio support
- Create small-scale and large-scale microservices applications using features supported by FastAPI
- Build event-driven and message-driven applications using the framework
- Create an asynchronous and synchronous data layer with both relational and NoSQL databases
- Perform numerical and symbolic computations with FastAPI
Who this book is for
This book is for Python web developers, advanced Python developers, and backend developers using Flask or Django who want to learn how to use the FastAPI framework to implement microservices. Readers familiar with the REST API and microservices will also benefit from this book. Some parts of the book contain general concepts, processes, and instructions that intermediate-level developers and Python enthusiasts can relate to as well.
Table of contents
- Building Python Microservices with FastAPI
- Contributors
- About the author
- About the reviewers
- Preface
- Part 1: Application-Related Architectural Concepts for FastAPI microservice development
- Chapter 1: Setting Up FastAPI for Starters
- Chapter 2: Exploring the Core Features
- Chapter 3: Investigating Dependency Injection
-
Chapter 4: Building the Microservice Application
- Technical requirements
- Applying the decomposition pattern
- Mounting the submodules
- Creating a common gateway
- Implementing the main endpoint
- Evaluating the microservice ID
- Applying the exception handlers
- Centralizing the logging mechanism
- Building the logging middleware
- Using the httpx module
- Using the requests module
- Applying the domain modeling approach
- Creating the layers
- Identifying the domain models
- Building the repository and service layers
- Managing a microservice’s configuration details
- Summary
- Part 2: Data-Centric and Communication-Focused Microservices Concerns and Issues
-
Chapter 5: Connecting to a Relational Database
- Technical requirements
- Preparing for database connectivity
- Creating CRUD transactions using SQLAlchemy
- Implementing async CRUD transactions using SQLAlchemy
- Using GINO for async transactions
- Using Pony ORM for the repository layer
- Building the repository using Peewee
- Applying the CQRS design pattern
- Summary
-
Chapter 6: Using a Non-Relational Database
- Technical requirements
- Setting up the database environment
- Applying the PyMongo driver for synchronous connections
- Creating async CRUD transactions using Motor
- Implementing CRUD transactions using MongoEngine
- Implementing async transactions using Beanie
- Building async repository for FastAPI using ODMantic
- Creating CRUD transactions using MongoFrames
- Summary
-
Chapter 7: Securing the REST APIs
- Technical requirements
- Implementing Basic and Digest authentication
- Implementing password-based authentication
- Applying JWTs
- Creating scope-based authorization
- Building the authorization code flow
-
Applying the OpenID Connect specification
- Using HTTPBearer
- Installing and configuring the Keycloak environment
- Setting the Keycloak realm and clients
- Creating users and user roles
- Assigning roles to clients
- Creating user permissions through scopes
- Integrating Keycloak with FastAPI
- Implementing the token verification
- Integrating Auth0 with FastAPI
- Integrating Okta with FastAPI
- Using built-in middlewares for authentication
- Summary
-
Chapter 8: Creating Coroutines, Events, and Message-Driven Transactions
- Technical requirements
- Implementing coroutines
- Creating asynchronous background tasks
- Understanding Celery tasks
- Building message-driven transactions using RabbitMQ
- Building publish/subscribe messaging using Kafka
- Implementing asynchronous Server-Sent Events (SSE)
- Building an asynchronous WebSocket
- Applying reactive programming in tasks
- Customizing events
- Summary
- Part 3: Infrastructure-Related Issues, Numerical and Symbolic Computations, and Testing Microservices
- Chapter 9: Utilizing Other Advanced Features
-
Chapter 10: Solving Numerical, Symbolic, and Graphical Problems
- Technical requirements
- Setting up the projects
- Implementing symbolic computations
- Creating arrays and DataFrames
- Performing statistical analysis
- Generating CSV and XLSX reports
- Plotting data models
- Simulating a BPMN workflow
- Using GraphQL queries and mutations
- Utilizing the Neo4j graph database
- Summary
-
Chapter 11: Adding Other Microservice Features
- Technical requirements
- Setting up the virtual environment
- Checking the API properties
- Implementing open tracing mechanisms
- Setting up service registry and client-side service discovery
- Deploying and running applications using Docker
- Using Docker Compose for deployment
- Using NGINX as an API Gateway
- Integrating Flask and Django sub-applications
- Summary
- Index
- Other Books You May Enjoy
Product information
- Title: Building Python Microservices with FastAPI
- Author(s):
- Release date: August 2022
- Publisher(s): Packt Publishing
- ISBN: 9781803245966
You might also like
book
Building Python Web APIs with FastAPI
Discover FastAPI features and best practices for building and deploying high-quality web APIs from scratch Key …
video
REST APIs with Flask and Python in 2024
A REST API is an application that accepts data from clients and returns data back. For …
book
Python Concurrency with asyncio
Learn how to speed up slow Python code with concurrent programming and the cutting-edge asyncio library. …
book
Python for DevOps
Much has changed in technology over the past decade. Data is hot, the cloud is ubiquitous, …