Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Building Data Science Applications with FastAPI

You're reading from  Building Data Science Applications with FastAPI

Product type Book
Published in Oct 2021
Publisher Packt
ISBN-13 9781801079211
Pages 426 pages
Edition 1st Edition
Languages
Author (1):
François Voron François Voron
Profile icon François Voron

Table of Contents (19) Chapters

Preface Section 1: Introduction to Python and FastAPI
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 Section 2: Build and Deploy a Complete Web Backend with FastAPI
Chapter 6: Databases and Asynchronous ORMs Chapter 7: Managing Authentication and Security in FastAPI Chapter 8: Defining WebSockets for Two-Way Interactive Communication in FastAPI Chapter 9: Testing an API Asynchronously with pytest and HTTPX Chapter 10: Deploying a FastAPI Project Section 3: Build a Data Science API with Python and FastAPI
Chapter 11: Introduction to NumPy and pandas Chapter 12: Training Machine Learning Models with scikit-learn Chapter 13: Creating an Efficient Prediction API Endpoint with FastAPI Chapter 14: Implement a Real-Time Face Detection System Using WebSockets with FastAPI and OpenCV Other Books You May Enjoy

Communicating with a SQL database with Tortoise ORM

When dealing with relational databases, you might wish to abstract away the SQL concepts and only deal with proper objects from the programming language. That's the main motivation behind ORM tools. In this section, we'll examine how to work with Tortoise ORM, which is a modern and asynchronous ORM that fits nicely within a FastAPI project. It's greatly inspired by the Django ORM; so, if you've ever worked with it, you'll probably be on familiar ground.

As usual, the first step is to install the library using the following command:

$ pip install tortoise-orm

If you need drivers for database engines such as PostgreSQL or MySQL, you can install them, as explained in the documentation at https://tortoise-orm.readthedocs.io/en/latest/getting_started.html#installation. We're now ready to work!

Creating database models

The first step is to create the Tortoise model for your entity. This is a...

lock icon The rest of the chapter is locked
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 $15.99/month. Cancel anytime}