Book Image

Building Data Science Applications with FastAPI - Second Edition

By : François Voron
3 (1)
Book Image

Building Data Science Applications with FastAPI - Second Edition

3 (1)
By: François Voron

Overview of this book

Building Data Science Applications with FastAPI is the go-to resource for creating efficient and dependable data science API backends. This second edition incorporates the latest Python and FastAPI advancements, along with two new AI projects – a real-time object detection system and a text-to-image generation platform using Stable Diffusion. The book starts with the basics of FastAPI and modern Python programming. You'll grasp FastAPI's robust dependency injection system, which facilitates seamless database communication, authentication implementation, and ML model integration. As you progress, you'll learn testing and deployment best practices, guaranteeing high-quality, resilient applications. Throughout the book, you'll build data science applications using FastAPI with the help of projects covering common AI use cases, such as object detection and text-to-image generation. These hands-on experiences will deepen your understanding of using FastAPI in real-world scenarios. By the end of this book, you'll be well equipped to maintain, design, and monitor applications to meet the highest programming standards using FastAPI, empowering you to create fast and reliable data science API backends with ease while keeping up with the latest advancements.
Table of Contents (21 chapters)
1
Part 1: Introduction to Python and FastAPI
7
Part 2: Building and Deploying a Complete Web Backend with FastAPI
13
Part 3: Building Resilient and Distributed Data Science Systems with FastAPI

Installing Python packages with pip

As we said earlier, pip is the built-in Python package manager that will help us install third-party libraries.

A word on alternate package managers such as Poetry, Pipenv, and Conda

While exploring the Python community, you may hear about alternate package managers such as Poetry, Pipenv, and Conda. These managers were created to solve some issues posed by pip, especially around sub-dependencies management. While they are very good tools, we’ll see in Chapter 10, Deploying a FastAPI Project, that most cloud hosting platforms expect dependencies to be managed with the standard pip command. Therefore, they may not be the best choice for a FastAPI application.

To get started, let’s install FastAPI and Uvicorn:

(venv) $ pip install fastapi "uvicorn[standard]"

We’ll talk about it in later chapters, but Uvicorn is required to run a FastAPI project.

What does “standard” stand for after “uvicorn”?

You probably noticed the standard word inside square brackets just after uvicorn. Sometimes, some libraries have sub-dependencies that are not required to make the library work. Usually, they are needed for optional features or specific project requirements. The square brackets are here to indicate that we want to install the standard sub-dependencies of uvicorn.

To make sure the installation worked, we can open a Python interactive shell and try to import the fastapi package:

(venv) $ python>>> from fastapi import FastAPI

If it passes without any errors, congratulations, FastAPI is installed and ready to use!