
FastAPI vs Flask performance comparison
If you are running Python in production , you will almost certainly have to decide which web framework to use. Let’s consider a rudimentary Hello world based test comparing the performance of two popular web frameworks for Python - FastAPI and Flask . I will intentionally use Docker for benchmarking as most deployments today will explicitly or implicitly rely on Docker. For Flask, I will use this Dockerfile 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 # Build: docker buildx build -t python-flask -f Dockerfile_python . # Size: docker image inspect python-flask --format='{{.Size}}' | numfmt --to=iec-i # Run: docker run -it --rm --cpus=1 --memory=100m -p 8001:8001 python-flask FROM python:3.13-slim AS base WORKDIR /app RUN pip3 install --no-cache-dir flask gunicorn SHELL ["/bin/bash", "-c"] RUN echo -e "\ from flask import Flask\n\ app = Flask(__name__)\n\ \ @app.get('/')\n\ def root():\n\ return 'Hello, World!'\n\ " > /app/web_server.py ENTRYPOINT ["gunicorn", "web_server:app", "--bind=0.0.0.0:8001", "--workers=4", "--threads=32"] And for FastAPI, I will use this ...