FastAPI is a Python web framework based on the Starlette microframework. With deep support for asyncio, FastAPI is indeed very fast. FastAPI also distinguishes itself with features like automatic OpenAPI (OAS) documentation for your API, easy-to-use data validation tools, and more. By Andrew Brookins.
In this tutorial, we’ll walk through the steps necessary to use Redis with FastAPI. We’re going to build IsBitcoinLit, an API that stores Bitcoin sentiment and price averages in Redis Stack using a timeseries data structure, then rolls these averages up for the last three hours.
The learning objectives of this tutorial:
- Learn how to install aioredis-py and connect to Redis
- Learn how to integrate aioredis-py with FastAPI
- Learn how to use Redis to store and query timeseries data
- Learn how to use Redis as a cache with aioredis-py
Putting all the pieces together, we now have a FastAPI app that can retrieve Bitcoin price and sentiment averages, store the averages in Redis, cache three-hour summary data in Redis, and serve the data to clients. You will also get video and all code samples use in tutorial. Nice one!
[Read More]