Web APIs

Libraries for building RESTful, GraphQL, and RPC APIs.

Type hints alone let FastAPI validate requests and document your API. Python API frameworks for Django include Django Ninja, which reads them too.

How to choose:

  • A new API, not tied to Django or Flask: FastAPI
  • Typed endpoints in a Django project: Django Ninja
  • CRUD endpoints over Django models, with a browsable API: Django REST framework
  • GraphQL types generated from Django models: Strawberry Django
  • msgspec, attrs, or dataclass schemas on Django: django-modern-rest
  • Flask resources grouped into namespaces, with Swagger docs: Flask-RESTX
  • marshmallow schemas on Flask blueprints: flask-smorest
  • A Flask app validated with Pydantic models or marshmallow: APIFlask
  • GraphQL on FastAPI or any other framework: Strawberry
  • An OpenAPI spec written before the code: Connexion
  • Calls between services written in different languages: gRPC

Listed in editorial order, grouped by use case. Click a column header to re-sort the whole list.

Press / to search. Tags open their category. Click a row for details.

Search and filter

Results

Row number Tags

Django 4 projects

A powerful and flexible toolkit to build web APIs.
Fast, Django REST framework based on type hints and Pydantic.
vitalik/github.com/vitalik/django-ninja /9,228 stars /
Strawberry GraphQL integration with Django.
Modern REST with speed, types, async, msgspec, pydantic and other goodies.

Flask 3 projects

Fully featured framework for fast, easy and documented API development with Flask.
A Flask/Marshmallow-based REST API framework with automatic OpenAPI documentation.
A lightweight Python web API framework based on Flask, supporting marshmallow schemas and Pydantic models.
apiflask/github.com/apiflask/apiflask /1,140 stars /

Framework Agnostic 3 projects

A modern, fast web framework for building APIs with standard Python type hints.
fastapi/github.com/fastapi/fastapi /104,390 stars /
A GraphQL library that leverages Python type annotations for schema definition.
A spec-first framework that handles requests based on your OpenAPI specification.
spec-first/github.com/spec-first/connexion /4,612 stars /

RPC 1 project

HTTP/2-based RPC framework with Python bindings, built by Google.
grpc/github.com/grpc/grpc /45,410 stars /

Web APIs guide

FastAPI is based on standard Python type hints. Declare path, query, and body parameters as typed function arguments, and it validates them and serves interactive docs at /docs. As the app grows, split it into modules with APIRouter, a "mini FastAPI".

Django Ninja was heavily inspired by FastAPI and integrates with Django's core and ORM. You declare parameter and body types once, as function arguments, and the interactive docs show up at /api/docs. For a bigger project, create an api.py with a Router in each Django app.

Django REST framework splits an API into serializers for the representation, viewsets for the behavior, and routers for the URLs. Viewsets get you running quickly and keep URLs consistent across a large API, while plain views are more explicit. For OpenAPI schemas, its docs recommend drf-spectacular.

APIFlask has you use APIFlask instead of Flask, then declare request and response schemas with @app.input and @app.output. flask-smorest organizes resources as MethodView classes in blueprints, with marshmallow schemas on Blueprint.arguments and Blueprint.response. Flask-RESTX splits your app into reusable namespaces, much like blueprints, and describes them for Swagger through decorators.

Strawberry builds on dataclasses and type hints, and FastAPI's docs recommend it for GraphQL. Before going to production, disable GraphiQL and introspection, and turn on Strawberry's security extensions that limit query depth, aliases, and tokens.

Strawberry Django creates GraphQL types from your Django models. Add its DjangoOptimizerExtension, which calls select_related() and prefetch_related() for you to avoid N+1 queries.

Connexion flips the usual order: you write the OpenAPI spec first, then the code, and Connexion validates requests against the spec. Each operationId in the spec names the Python function that handles it. Start new projects on AsyncApp, or on FlaskApp to use the Flask ecosystem.

gRPC lets you define a service once in a .proto file and generate clients and servers in any language it supports. For asyncio code, gRPC has grpc.aio.

Know a project that belongs here?

Tell us what it does and why it stands out.