My Tech Stack for building lean and mean HTTP APIs with Python — Aryan Iyappan

When it comes to building lightweight and efficient HTTP APIs, Python offers a fantastic ecosystem of tools that enable you to create robust, scalable, and maintainable backends. In this post, I'll walk you through my tech stack for building lean and mean APIs with Python. Each component has been chosen to maximize efficiency, readability, and modern best practices.

Nov 20, 2024 · 6 min read

Tags: tech stack, python, http, backend

When it comes to building lightweight and efficient HTTP APIs, Python offers a fantastic ecosystem of tools that enable you to create robust, scalable, and maintainable backends.

Personally, as an aspiring technical startup founder, iteration speed is crucial when building apps, which this tech stack reflects. Python, in particular, strikes the perfect balance for me. Not only am I familiar and enjoy programming with it, but it also allows for insanely fast iteration speeds, making it my ideal choice for crafting APIs.

Plus, there is no bloat across the tech stack. Each framework in my stack is purpose-built, doing exactly what it’s meant to do—nothing more, nothing less.

Toy Story meme: Buzz Lightyear shows a worried Woody “Type hints… type hints everywhere”

I’ve grown to appreciate type hints in Python for how they reduce bugs and simplify development. By explicitly defining expected types for variables and functions, my code becomes easier to understand and maintain. Tools like mypy catch errors early, while smarter IDE suggestions speed up iteration. Type hints add clarity and make refactoring smoother as projects grow—a small change with a big impact.

The tools in my tech stack reflect this, they make the most out of type hints wherever possible.

FastAPI: Web Framework

FastAPI is my go-to microframework for HTTP API development. It strikes the perfect balance between minimalism and power, providing a robust foundation for building APIs without the overhead of full-stack frameworks like Django.

Key Features

Why not Django? Django shines for full-stack development with HTML templates and admin panels, but for APIs, FastAPI's modern features and speed make it a clear winner. I usually use a separate framework for the frontend like React/ Next.js, so this works for me.

SQLAlchemy: Database Access

For database interactions, I use SQLAlchemy, the defacto Object-Relational Mapping (ORM) library in Python. It provides a seamless way to work with databases through Python objects, abstracting away raw SQL.

Key Features

Alembic: Database Migrations

Database migrations are a crucial part of any backend project, and that's where Alembic comes in.

As a companion to SQLAlchemy, it provides:

Pydantic: Data Validation/ Parsing

FastAPI and Pydantic are a match made in heaven. Pydantic is a data validation library that ensures your inputs are clean and follow the expected structure. It is also very performant, with its core being written in Rust.

Why Pydantic?

Uvicorn: ASGI Web Server

FastAPI requires an ASGI server to run, and Uvicorn is the perfect choice. It’s a lightning-fast ASGI server that supports HTTP/2 and WebSockets, ensuring your app is future-proof. For ultimate performance, I always use uvloop (a blazing fast asyncio event loop) and httptools (a fast HTTP parser) alongside Uvicorn whenever possible.

Why Uvicorn?

[!NOTE]

Deploying to AWS Lambda?

For serverless environments like AWS Lambda, I use Mangum to seamlessly adapt my FastAPI application to the Lambda runtime, making deployments both simple and efficient.

An alternative I’m eager to explore is Granian, an ASGI server written from scratch in Rust. Its design promises exceptional performance and scalability, making it an exciting option for future projects.

Structlog: Logging with Context

Logging is essential for debugging and monitoring, and Structlog brings clarity to this task.

Unlike Python’s built-in logging, Structlog provides:

Taskiq: Task Queues for Background Processing

For handling background tasks or worker queues, Taskiq is my library of choice. It integrates seamlessly with FastAPI to offload long-running operations. It also has support for advanced features such as global middlewares and dependency injection.

Use cases include:

Taskiq’s lightweight approach makes it a strong competitor to Celery for smaller to medium-scale applications.

PyTest: Pythonic Testing

PyTest is my preferred testing framework. It’s simple, extensible, and designed with Pythonic principles. I would say that it is far better than the rather old and unintuitive built-in testing library Python provides.

Plug and play- use when required

I use the following frameworks in my tech stack only when there is an explicit need for it:

Strawberry GraphQL: GraphQL Library

I use GraphQL in my applications whenever there is a need for intense data fetching/ a need to support multiple clients from the same API. When I choose to use GraphQL in my tech stack, the best tool in the Python ecosystem is Strawberry GraphQL.

Key Features