Most Python web frameworks make you choose between testability and convenience. You either have clean code with complex test setup, or you use global state and hope your tests don’t interfere with each other. FastAPI’s Depends() solves this elegantly. Here is an example how you would use it in your API: What’s happening here: Type-safe – Your editor knows repo is a SnippetRepository. Full autocomplete, type checking works. Automatic cleanup – The context manager ensures the database session closes, even if an exception occurs. No global state – Every request gets its own session. No risk of one request interfering with another. Testable –…
Topic Archive
FastAPI
-
-
From Backend to Frontend: Connecting FastAPI and Streamlit
·
·
5 min readIn my previous Pybites article, I showed how I built and deployed a book tracking API using FastAPI, Docker, and Fly.io. That project taught me a lot about backend development, containers, and deploying modern APIs. But a backend alone isn’t enough—users need an interface. And FastAPI’s Swagger UI, while useful for testing, just isn’t user-friendly enough for everyday use. So, I decided to build a frontend. My goal? A fast, Python-based UI with minimal hassle. That’s when I turned to Streamlit. In this article, I’ll explain why I used Streamlit and how I was able to connect my deployed backend…
-
FastAPI Deployment Made Easy with Docker and Fly.io
·
·
8 min readFor the PDM program I worked on a FastAPI project to track books using the Google Book API and also provide AI powered recommendations using Marvin AI. As the project came closer to deployment, I knew that I wanted to try out containerization for a reliable and repeatable way to deploy. I chose Docker due to its widespread use, open-source nature, and consistent behavior across environments.If you’re new to Docker or looking for a straightforward guide to deploying a FastAPI app with Docker and Fly.io, this post is for you. FastAPI Set Up for Docker Before deploying the app, we…
-
In this article I will show you how to deploy a FastAPI app as a function in Azure. Prerequisites are that you have an Azure account and have the Azure CLI installed (see here). Setup Azure First you need to login to your Azure account: It should show your subscriptions and you select the one you want to use. Create a resource group Like this: A resource group is a container that holds related resources for an Azure solution (of course use your own names throughout this guide). It comes back with the details of the resource group you just…