This is a pragmatic introduction to FastAPI—a modern Python web framework. It’s also a story of how, now and then, the bright and shiny objects that we stumble across can turn out to be very useful. A silver bullet is nice to have when you encounter a werewolf. (And you will encounter werewolves later in this book.)
Table Of Contents
Preface
I started programming scientific applications in the mid-1970s. And after I first met Unix and C on a PDP-11 in 1977, I had a feeling that this Unix thing might catch on. In the ’80s and early ’90s, the internet was still noncommercial, but already a good source for free software and technical info. And when a web browser called Mosaic was distributed on the baby open internet in 1993, I had a feeling that this web thing might catch on.
When I started my own web development company a few years later, my tools were the usual suspects at the time: PHP, HTML, and Perl. On a contract job a few years later, I finally experimented with Python and was surprised at how quickly I was able to access, manipulate, and display data. In my spare time over two weeks, I was able to replicate most of a C application that had taken four developers a year to write. Now I had a feeling that this Python thing might catch on.
After that, most of my work involved Python and its web frameworks, mostly Flask and Django. I particularly liked the simplicity of Flask and preferred it for many jobs. But just a few years ago, I spied something glinting in the underbrush: a new Python web framework called FastAPI, written by Sebastián Ramírez.
As I read his (excellent) documentation, I was impressed by the design and thought that had gone into it. In particular, his history page showed how much care he had taken evaluating alternatives. This was not an ego project or a fun experiment, but a serious framework for real-world development. Now I had a feeling that this FastAPI thing might catch on.
I wrote a biomedical API site with FastAPI, and it went so well that a team of us rewrote our old core API with FastAPI in the next year. This is still in production and has held up well. Our group learned the basics that you’ll read in this book, and all felt that we were writing better code, faster, with fewer bugs. And by the way, some of us had not written in Python before, and only I had used FastAPI.
So when I had an opportunity to suggest a follow-up to my Introducing Python book to O’Reilly, FastAPI was at the top of my list. In my opinion, FastAPI will have at least the impact that Flask and Django have had, and maybe more.
As I’ve mentioned, the FastAPI website itself provides world-class documentation, including many details on the usual web topics: databases, authentication, deploy‐ ment, and so on. So why write a book?
This book isn’t meant to be exhaustive because, well, that’s exhausting. It is meant to be useful—to help you quickly pick up the main ideas of FastAPI and apply them. I will point out various techniques that required some sleuthing and offer advice on day-to-day best practices.
I start each chapter with a Preview of what’s coming. Next, I try not to forget what I just promised, offering details and random asides. Finally, there’s a brief digestible Review.
As the saying goes, “These are the opinions on which my facts are based.” Your expe‐ rience will be unique, but I hope that you will find enough of value here to become a more productive web developer.
Download
See also
- Software Exorcism: A Handbook for Debugging and Optimizing Legacy Code by Bill Blunden (2003)
- Hormones and the Endocrine System: Textbook of Endocrinology by Bernhard Kleine (2016)
- Genetics: A Conceptual Approach 6e by Benjamin A. Pierce (2017)
- A Functional Approach to Java by Ben Weidig (2022)
- Calculus of variations and optimal control by Amol Sasan (2005)