Building Data Science Applications with FastAPI
eBook - ePub

Building Data Science Applications with FastAPI

Francois Voron

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

Building Data Science Applications with FastAPI

Francois Voron

Book details
Book preview
Table of contents
Citations

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

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
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.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
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.
Do you support text-to-speech?
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.
Is Building Data Science Applications with FastAPI an online PDF/ePUB?
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 & Web Services & APIs. We have over one million books available in our catalogue for you to explore.

Information

Year
2021
ISBN
9781801074186
Edition
1

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