Skip to content


Migrating from Flask to FastAPI, Part 1


At Forethought we mainly use Python to develop all the product components and services. It's the perfect language for us as we use complex machine learning, data processing, APIs, and others. Python works great for those use cases, and having a common programming language facilitates the development and interaction between all the teams.

Up to a year ago, most of the APIs and backend services were built with Flask, it worked great for us and allowed us to keep growing the products. However, for our particular use cases, mainly building APIs to handle data, it made sense to migrate to FastAPI to get the extra benefits like improved developer productivity, increased code quality, correctness and certainty, automatic data validation, serialization, and documentation, etc.

Nevertheless, we have a huge codebase, the products are constantly evolving. We have many PRs merged daily from the dozens of engineers across all teams, and we release multiple times a day.

In many cases we have to accomodate the code and systems to fit our customer's needs and all the integrations we support, we need to be able to communicate with different APIs, support different authentication methods for our APIs, support backward compatibility, etc. This also means that the code inherently requires some complexity and advanced patterns.

All this makes a migration challenging, and a moving target as well. But now that we have successfully migrated to FastAPI for around a year and we can see the benefits, we want to share the different techniques we used, things we learned, and different tips and tricks that could be useful to you.

This blog series is made of 3 parts, you're reading the first, preparing the ground for the actual migration.