In the beginning, I've been recruiting to one of the companies and I have received a recruitment assignment which was about creating a small 2h p

rogulski.it | My experience with FastAPI and async database connection

submited by
Style Pass
2021-06-07 07:30:05

In the beginning, I've been recruiting to one of the companies and I have received a recruitment assignment which was about creating a small 2h project with Python and framework of choice.

I've chosen a FastAPI because I have never used it before but I have always wanted to learn it (I think that it is a good idea to check yourself with new technology). In my previous company, I did not have much time to use the new tech stack so every occasion is good.

Here is my project if somebody would be interested. This project used a base sync setup due to best practices from tiangolo FastAPI documentation.

This article will focus on showing a configuration of FastAPI using asyncio PostgreSQL setup (using SQLAlchemy <1.4 with databases) and how to test it. Setup will include alembic to perform migrations.

This is a small and modified example of how it can be used. I have started using this configuration in production environments and it works like a charm. Unfortunately, not all packages are supporting asyncio yet but for most of my use cases, most things are covered e.g. async requests to other services.

Leave a Comment