Chapter 3. FastAPI Tour

FastAPI is a modern, fast (high-performance) web framework for building APIs with Python 3.6+ based on standard Python type hints.

Sebastián Ramírez, creator of FastAPI

Preview

FastAPI was announced in 2018 by Sebastián Ramírez. It’s more modern in many senses than most Python web frameworks—taking advantage of features that have been added to Python 3 in the last few years. This chapter is a quick overview of FastAPI’s main features, with emphasis on the first things that you’ll want to know: how to handle web requests and responses.

What Is FastAPI?

Like any web framework, FastAPI helps you build web applications. Every framework is designed to make some operations easier—by features, omissions, and defaults. As the name implies, FastAPI targets development of web APIs, although you can use it for traditional web content applications as well.

The FastAPI website claims these advantages:

Performance

As fast as Node.js and Go in some cases, unusual for Python frameworks.

Faster development

No sharp edges or oddities.

Better code quality

Type hinting and models help reduce bugs.

Autogenerated documentation and test pages

Much easier than hand-editing OpenAPI descriptions.

FastAPI uses the following:

  • Python type hints

  • Starlette for the web machinery, including async support

  • Pydantic for data definitions and validation

  • Special integration to leverage and extend the others

This combination makes a pleasing development environment for ...

Get FastAPI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.