> Markdown version of [/videos/506-build-your-backend-using-fastapi?t=680](https://www.wearedevelopers.com/videos/506-build-your-backend-using-fastapi?t=680). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # Build your backend using FastAPI Tired of heavy Django boilerplate and manual endpoint testing? Build your next machine learning backend with FastAPI to get out-of-the-box data validation and automatic interactive documentation. - **Speakers:** Ashmi Banerjee - **Event:** World Congress 2022 - **Published:** June 15, 2022 - **Duration:** 23:10 - **URL:** https://www.wearedevelopers.com/videos/506-build-your-backend-using-fastapi ## Summary Modern web architecture has shifted away from traditional server-rendered HTML toward a decoupled approach, where content delivery networks handle static assets while backend servers deliver dynamic content via JSON. This architectural evolution necessitates efficient API development, particularly for bridging the gap between data science and application engineering. Wrapping complex machine learning models in a REST API solves the common challenge of model accessibility, preventing the need to download heavy models to local devices and allowing seamless integration across internal applications. When evaluating Python backend frameworks for this task, traditional options present distinct trade-offs. Django offers a robust, "batteries included" environment but carries heavy boilerplate code, making it overly complex for pure API development. Flask provides a lightweight alternative but often requires writing HTML or relying on external tools like Postman to test endpoints. FastAPI emerges as the optimal modern solution, allowing developers to focus entirely on business logic. It provides automatic interactive documentation via Swagger UI, eliminating the need for third-party testing tools, and features inbuilt data validation to catch type errors immediately, saving hours of debugging time. Implementing a machine learning backend with FastAPI involves defining straightforward REST endpoints and running the application via a Uvicorn server. Furthermore, asynchronous support ensures high-performing parallelization. Transitioning a finished model from development to production requires strict post-development practices, including thorough endpoint testing, cloud deployment, and Docker containerization to ensure consistent environments and eliminate the persistent "works on my machine" anti-pattern. **Keywords:** python backend frameworks, fastapi rest endpoints, machine learning model serving, modern web architecture, dynamic json rendering, django boilerplate code, flask api development, swagger ui documentation, inbuilt data validation, asyncio parallelization, uvicorn server implementation, docker containerization, cloud deployment strategies, rest api accessibility ## Chapters 1. **Prerequisites for building backends with FastAPI** (00:05) — Basic knowledge of Python, machine learning, and web development provides the foundation for building API backends. 1. **Traditional versus modern web architecture for rendering pages** (02:46) — Modern web architecture pairs content delivery networks for static content with API servers returning JSON for dynamic components. 1. **Comparing Python backend frameworks for web development** (05:15) — Django offers full-stack robustness while Flask and FastAPI provide lightweight alternatives with reduced boilerplate for API-focused applications. 1. **Key features and advantages of using FastAPI** (11:20) — FastAPI provides automatic interactive documentation, asynchronous IO support, and rapid development capabilities for REST endpoints. 1. **Serving a machine learning image classifier via API** (12:42) — Wrapping a pre-trained machine learning model inside an API makes it broadly accessible across applications without local downloads. 1. **Interactive demonstration of the image classifier API** (18:02) — An interactive Swagger interface allows testing the endpoints directly using image URLs to evaluate real-time model predictions. 1. **Testing, containerization, and deployment for API applications** (19:14) — Moving an application to production requires thorough testing, Docker containerization, and safe deployment to a commercial cloud service. 1. **Model serving options and asynchronous function requirements** (21:36) — Evaluating tools like TensorFlow Serve offers alternatives to FastAPI while highlighting specific rules for asynchronous function declarations. ## Related Moments - [Introduction to the fast API web framework](https://www.wearedevelopers.com/videos/462-intro-to-fastapi) (from "Intro to FastAPI") - [Introduction to building APIs with Flask](https://www.wearedevelopers.com/videos/563-no-more-node-build-apis-with-flask-and-test-it-with-postman) (from "No more Node: Build APIs with Flask and test it with Postman") - [Exploring the tiered architecture of modern machine learning stacks](https://www.wearedevelopers.com/videos/154-machine-learning-for-software-developers-and-knitters) (from "Machine Learning for Software Developers (and Knitters)") - [Connecting frontends via a FastAPI proxy backend layer](https://www.wearedevelopers.com/videos/1918-building-and-deploying-multi-agent-systems-with-adk-and-vertex-ai) (from "Building and Deploying Multi-Agent Systems with ADK and Vertex AI") - [Code and architecture for building the discount application](https://www.wearedevelopers.com/videos/857-convert-batch-code-into-streaming-with-python) (from "Convert batch code into streaming with Python") - [Deploying and testing the AI inference service](https://www.wearedevelopers.com/videos/1609-from-code-to-motion-building-an-autonomous-hat-hunting-robot-with-kubernetes-ml) (from "From Code to Motion: Building an Autonomous Hat-Hunting Robot with Kubernetes & ML") ## Related Articles - [The 7 Most Popular Backend Frameworks for Developers](https://www.wearedevelopers.com/magazine/403-the-7-most-popular-backend-frameworks-for-developers) - [MLops – Deploying, Maintaining And Evolving Machine Learning Models in Production](https://www.wearedevelopers.com/magazine/115-mlops-deploying-maintaining-and-evolving-machine-learning-models-in-production) - [20 Essential Tools For Backend Development](https://www.wearedevelopers.com/magazine/218-20-essential-tools-for-backend-development) - [Building AI Solutions with Rust and Docker](https://www.wearedevelopers.com/magazine/494-building-ai-solutions-with-rust-and-docker) ## Related Jobs - [Senior AI Serving Engineer, Backend](https://www.wearedevelopers.com/jobs/48414-senior-ai-serving-engineer-backend) at **Sciforium** - [Software Engineer, Fullstack](https://www.wearedevelopers.com/jobs/48415-software-engineer-fullstack) at **Sciforium** - [Software Engineer, Python (Asset Pricing & Hedging)](https://www.wearedevelopers.com/jobs/ext/2772280-software-engineer-python-asset-pricing-hedging) at **Bitpanda** - [Model Implementation Engineer](https://www.wearedevelopers.com/jobs/48421-model-implementation-engineer) at **Sciforium** - [Lead Software Engineer, Model Serving Platform](https://www.wearedevelopers.com/jobs/48413-lead-software-engineer-model-serving-platform) at **Sciforium** - [Backend Engineer, Python (Web3)](https://www.wearedevelopers.com/jobs/ext/1934515-backend-engineer-python-web3) at **Bitpanda**