django_for_startups icon indicating copy to clipboard operation
django_for_startups copied to clipboard

Convert to FastApi

Open colin99d opened this issue 7 months ago • 1 comments
trafficstars

Fastapi is superior to Django.

  1. Speed & Performance (asynchronous by design)

    • FastAPI is built on top of Starlette and Uvicorn, and it’s designed with async I/O from the start. This makes FastAPI highly performant for network-bound operations—ideal for modern, API-driven or microservices architectures where you might be handling many concurrent connections.
    • Django can also handle asynchronous code via ASGI (using Django Channels or async features added in newer releases), but traditionally it’s geared more toward synchronous behavior out of the box and has deeper legacy patterns that were originally built around WSGI.
  2. Focus on APIs and Microservices

    • FastAPI is minimalist in scope. It focuses on building web APIs quickly with a small, understandable core, making it a good fit if you’re primarily developing REST APIs or microservices.
  3. Type Hints & Automatic Documentation

    • FastAPI encourages (and, in many ways, relies on) Python type hints. It uses these type hints to generate interactive API docs automatically via OpenAPI and Swagger UI, and to perform validation. This can reduce boilerplate and keep your code more concise and self-documented.
    • Django does not rely on type hints in the same manner. While you can still use type hints in Django code, it doesn’t automatically generate documentation or validation from them.
  4. Learning Curve and Modern Syntax

    • FastAPI has a straightforward, modern syntax that’s typically easier to learn for developers already comfortable with async Python. Its documentation is very direct, and building a simple API is usually just a few lines of code.
  5. Community and Ecosystem

    • FastAPI is newer (2018) but rapidly growing. It benefits from the Python community’s shift toward async frameworks, and it integrates well with the rich set of libraries built for asyncio and the modern Python toolchain.

Other reasons FastApi is better

  • You want a high-performance, async API.
  • You want automatic validation and documentation generated directly from Python type hints.
  • You prefer a lightweight framework for microservices and quick APIs without excess overhead.

colin99d avatar Apr 10 '25 04:04 colin99d

@colin99d This repository is basically frozen at this point because it's the source code for my eBook, so making any changes would require re-writing that.

That said, at some point I'm going to release an updated version of this as a Django template, which is intended to serve as a living version of this. You're welcome to fork this to make a FastAPI version, similar to what nuvic did here for Flask: https://github.com/nuvic/flask_for_startups

Alternatively, you could wait until I get around to finishing the updated version, and then fork that. (The main differences are that the new version will be Dockerized and will include terraform to deploy to AWS.)

Alex3917 avatar Apr 10 '25 13:04 Alex3917