Building Data Science Applications with FastAPI
eBook - ePub

Building Data Science Applications with FastAPI

  1. 426 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Building Data Science Applications with FastAPI

About this book

Get well-versed with FastAPI features and best practices for testing, monitoring, and deployment to run high-quality and robust data science applicationsKey Features• Cover the concepts of the FastAPI framework, including aspects relating to asynchronous programming, type hinting, and dependency injection• Develop efficient RESTful APIs for data science with modern Python• Build, test, and deploy high performing data science and machine learning systems with FastAPIBook DescriptionFastAPI is a web framework for building APIs with Python 3.6 and its later versions based on standard Python-type hints. With this book, you'll be able to create fast and reliable data science API backends using practical examples.This book starts with the basics of the FastAPI framework and associated modern Python programming language concepts. You'll be taken through all the aspects of the framework, including its powerful dependency injection system and how you can use it to communicate with databases, implement authentication and integrate machine learning models. Later, you'll cover best practices relating to testing and deployment to run a high-quality and robust application. You'll also be introduced to the extensive ecosystem of Python data science packages. As you progress, you'll learn how to build data science applications in Python using FastAPI. The book also demonstrates how to develop fast and efficient machine learning prediction backends and test them to achieve the best performance. Finally, you'll see how to implement a real-time face detection system using WebSockets and a web browser as a client.By the end of this FastAPI book, you'll have not only learned how to implement Python in data science projects but also how to maintain and design them to meet high programming standards with the help of FastAPI.What you will learn• Explore the basics of modern Python and async I/O programming• Get to grips with basic and advanced concepts of the FastAPI framework• Implement a FastAPI dependency to efficiently run a machine learning model• Integrate a simple face detection algorithm in a FastAPI backend• Integrate common Python data science libraries in a web backend• Deploy a performant and reliable web backend for a data science applicationWho this book is forThis Python data science book is for data scientists and software developers interested in gaining knowledge of FastAPI and its ecosystem to build data science applications. Basic knowledge of data science and machine learning concepts and how to apply them in Python is recommended.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Building Data Science Applications with FastAPI by Francois Voron in PDF and/or ePUB format, as well as other popular books in Computer Science & Data Processing. We have over one million books available in our catalogue for you to explore.

Information

Section 1: Introduction to Python and FastAPI

After setting up the development environment, we’ll introduce the specificities of Python before starting to explore the basic features of FastAPI and running our first REST API.
This section comprises the following chapters:
  • Chapter 1, Python Development Environment Setup
  • Chapter 2, Python Programming Specificities
  • Chapter 3, Developing a RESTful API with FastAPI
  • Chapter 4, Managing pydantic Data Models in FastAPI
  • Chapter 5, Dependency Injections in FastAPI

Chapter 1: Python Development Environment Setup

Before we can get started on our FastAPI journey, we need to configure a clean and efficient Python environment. This chapter will show you the best practices and conventions that Python developers use daily to run their projects.
By the end of this chapter, you'll be able to run Python projects and install third-party dependencies in a contained environment that won't raise conflicts if you happen to work on another project that uses different versions of the Python language or different dependencies.
In this chapter, we're going to cover the following main topics:
  • Installing a Python distribution using pyenv
  • Creating a Python virtual environment
  • Installing Python packages with pip
  • Installing the HTTPie command-line utility

Technical requirements

Throughout this book, we'll assume you have access to a Unix-based environment, such as a Linux distribution or macOS.
If they haven't done so already, macOS users should install the Homebrew package (https://brew.sh), which helps a lot in installing command-line tools.
If you are a Windows user, you should enable Windows Subsystem for Linux (https://docs.microsoft.com/windows/wsl/install-win10), WSL, and install a Linux distribution (such as Ubuntu) that will run alongside the Windows environment, which should give you access to all the required tools. There are currently two versions of WSL, WSL and WSL2. Depending on your Windows version, you might not be able to install the newest version. However, we do recommend using WSL2 if your Windows installation supports it.

Installing a Python distribution using pyenv

Python is already bundled with most Unix environments. To ensure this is the case, you can run this command in a command line to show the version of the currently installed Python:
$ python3 --version
The output version displayed will vary depending on your system. You may think that this is enough to get started, but it poses an important issue: you can't choose the Python version for your project. Each Python version introduces new features and breaking changes. Thus, it's important to be able to switch to a recent version for new projects to take advantage of the new features but still be able to run older projects that may not be compatible. This is why we need pyenv.
pyenv (https://github.com/pyenv/pyenv) is a tool that helps you manage and switch between multiple Python versions on your system. It allows you to set a default Python version for your whole system but also per project.
Beforehand, you need to install several build dependencies on your system to allow pyenv to compile Python on your system. The official documentation provides clear guidance on this (https://github.com/pyenv/pyenv/wiki#suggested-build-environment), but here are the commands you should run:
  1. Install the build dependencies:
    • macOS users, use this:
      $ brew install openssl readline sqlite3 xz zlib
    • Ubuntu users, use this:
      $ sudo apt-get update; sudo apt-get install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
      Package managers
      Brew and APT are what are commonly known as package managers. Their role is to automate the installation and management of software on your system. Thus, you don't have to worry about where to download them and how to install and uninstall them. The commands just tell the package manager to update its internal package index and then install the list of required packages.
  2. Install pyenv:
    $ curl https://pyenv.run | bash
    Tip
    If you are a macOS user, you can also install it with Homebrew: brew install pyenv.
  3. This will download and execute an installation script that will handle everything for you. At the end, it'll prompt you with some instructions to add some lines to your shell scripts so that pyenv is discovered properly by your shell:
    a. Open your ~/.profile script in nano, a simple command-line text edito...

Table of contents

  1. Building Data Science Applications with FastAPI
  2. Contributors
  3. Preface
  4. Section 1: Introduction to Python and FastAPI
  5. Chapter 1: Python Development Environment Setup
  6. Chapter 2: Python Programming Specificities
  7. Chapter 3: Developing a RESTful API with FastAPI
  8. Chapter 4: Managing Pydantic Data Models in FastAPI
  9. Chapter 5: Dependency Injections in FastAPI
  10. Section 2: Build and Deploy a Complete Web Backend with FastAPI
  11. Chapter 6: Databases and Asynchronous ORMs
  12. Chapter 7: Managing Authentication and Security in FastAPI
  13. Chapter 8: Defining WebSockets for Two-Way Interactive Communication in FastAPI
  14. Chapter 9: Testing an API Asynchronously with pytest and HTTPX
  15. Chapter 10: Deploying a FastAPI Project
  16. Section 3: Build a Data Science API with Python and FastAPI
  17. Chapter 11: Introduction to NumPy and pandas
  18. Chapter 12: Training Machine Learning Models with scikit-learn
  19. Chapter 13: Creating an Efficient Prediction API Endpoint with FastAPI
  20. Chapter 14: Implement a Real-Time Face Detection System Using WebSockets with FastAPI and OpenCV
  21. Other Books You May Enjoy