It seems like every month, a new Python web framework is launched - with a new
set of features, better performance, or a cleaner syntax than its predecessors.
One feature that often gets ignored, however, is OpenAPI support. We've talked
at great lengths about the benefits of OpenAPI - including
[marketing your API](/learning-center/how-to-promote-your-api-spectacular-openapi) -
but in short, OpenAPI generation via web framework is the best way to make sure
your API documentation matches your API implementation. It seems like newer
frameworks are starting to realize the importance of OpenAPI - with some
frameworks like Robyn,
[adding OpenAPI docs generation](https://github.com/sparckles/Robyn/releases/tag/v0.63.0)
as a part of the beta.

In this article, we will explore 20 of the most popular API frameworks and
libraries for building APIs with Python, that have support for generating
OpenAPI/Swagger specifications, either built-in or through an external
library/extension.

## 1. FastAPI

![FastAPI](/media/posts/2024-11-04-top-20-python-api-frameworks-with-openapi/image-1.png)

### What is FastAPI?

[FastAPI](https://fastapi.tiangolo.com/) is a modern, high-performance web
framework for building APIs with Python 3.6+ based on standard Python type
hints. It is designed for quick development and high efficiency. Zuplo is a
[proud sponsor](https://fastapi.tiangolo.com/#sponsors) of the FastAPI project,
to help drive API development in Python. Check out our
[guide to building, deploying, and securing a FastAPI API](/learning-center/fastapi-tutorial)
to get started with FastAPI.

### FastAPI OpenAPI/Swagger Support

- **Built-in Support**: FastAPI automatically generates OpenAPI (formerly
  Swagger) schemas from your code.
- **Interactive Documentation**: Provides
  [Swagger UI and ReDoc](https://fastapi.tiangolo.com/reference/openapi/docs/)
  interfaces out of the box, accessible via `/docs` and `/redoc` endpoints.

### FastAPI Pros and Cons

**Pros**

- **High Performance**: Comparable to NodeJS and Go, thanks to its use of
  asynchronous programming.
- **Automatic Documentation**: Generates OpenAPI schema and interactive docs
  automatically.
- **Ease of Use**: Developer-friendly with concise syntax.
- **Validation**: Uses Pydantic for data validation based on type hints.
- **Asynchronous Support**: Built on Starlette, supports async programming.

**Cons**

- **Learning Curve**: Requires understanding of Python type hints and async
  programming.
- **Relatively New**: Less mature than some older frameworks, though it has a
  growing community.

## 2. Django REST Framework (DRF)

### What is Django REST Framework?

[Django REST Framework](https://www.django-rest-framework.org/) is a powerful
and flexible toolkit for building Web APIs using Django, the popular high-level
Python web framework. Zuplo
[proudly sponsors](https://www.django-rest-framework.org/#funding) the DRF
project to continue improving the Django API development ecosystem.

### Django Rest Framework OpenAPI/Swagger Support

- **Third-Party Packages**: OpenAPI support via packages like
  [`drf-yasg`](https://github.com/axnsan12/drf-yasg/) (OpenAPI 2.x / Swagger)
  and [`drf-spectacular`](https://github.com/tfranzel/drf-spectacular/) (OpenAPI
  3.x).

### Django REST Framework Pros and Cons

**Pros**

- **Integration with Django**: Leverages Django's robust features like ORM,
  authentication.
- **Comprehensive**: Rich in features for serialization, authentication,
  permissions.
- **Community Support**: Large ecosystem and community.

**Cons**

- **Complexity**: Can be overkill for simple APIs.
- **Performance**: Potentially slower due to abstraction layers.

## 3. Flask

### What is Flask?

[Flask](https://flask.palletsprojects.com/en/stable/) is a micro web framework
written in Python. It is known for its simplicity and extensibility.

### Flask OpenAPI/Swagger Support

- **Extensions Required**: Uses extensions like
  [`APIFairy`](https://github.com/miguelgrinberg/APIFairy), or
  [`Flask-Smorest`](https://github.com/marshmallow-code/flask-smorest) for
  OpenAPI support.
- **Automatic Documentation**: These extensions can generate Swagger UI and
  OpenAPI specs.

### Flask Pros and Cons

**Pros**

- **Lightweight**: Minimalist core, easy to get started.
- **Flexible**: Highly extensible with numerous plugins.
- **Large Community**: Abundant resources and support.

**Cons**

- **Manual Setup**: Requires additional setup for features like OpenAPI support.
- **Inconsistent Extensions**: Varying quality and maintenance status among
  extensions.

## 4. Connexion

### What is Connexion?

[Connexion](https://connexion.readthedocs.io/en/latest/) is a framework that
automagically handles HTTP requests based on OpenAPI specification, built on top
of Flask.

### Connexion OpenAPI/Swagger Support

- **First-Class OpenAPI Integration**: Uses your OpenAPI specs to route requests
  and validate inputs.
- **Automatic Documentation**: Provides Swagger UI based on your OpenAPI files.

### Connexion Pros and Cons

**Pros**

- **API-First Development**: Encourages designing API contracts before
  implementation.
- **Input Validation**: Automatically validates requests against the OpenAPI
  schema.
- **Less Boilerplate**: Reduces code duplication.

**Cons**

- **Rigid Structure**: Requires maintaining OpenAPI specs in sync with code.
- **Complexity**: Can be challenging for those unfamiliar with
  API-first/Spec-first approaches.

## 5. Eve

### What is Eve?

[Eve](https://docs.python-eve.org/en/stable/) is an out-of-the-box REST API
framework powered by Flask, MongoDB, and Redis.

### Eve OpenAPI/Swagger Support

- **Extension Required**: Uses
  [`eve-swagger`](https://github.com/pyeve/eve-swagger) to generate
  Swagger/OpenAPI documentation.

### Eve Pros and Cons

**Pros**

- **Quick Setup**: Rapid API development with minimal configuration.
- **Data Handling**: Built-in support for MongoDB with data validation.
- **Features**: Supports pagination, sorting, filtering, and more.

**Cons**

- **Database Dependency**: Primarily designed for MongoDB.
- **Flexibility**: Less flexible if you need to deviate from its conventions.

## 6. Sanic

![Sanic](/media/posts/2024-11-04-top-20-python-api-frameworks-with-openapi/image-2.png)

### What is Sanic

[Sanic](https://sanic.dev/en/) is a Python 3.7+ web server and web framework
that is written to be fast. It allows for asynchronous request handling. Zuplo
is a [proud sponsor of Sanic](https://sanic.dev/en/), to help push the envelope
on Python API performance.

### Sanic OpenAPI/Swagger Support

- **Built-in Support**: Out of the box, Sanic Extensions provides
  [automatically generated API documentation](https://sanic.dev/en/plugins/sanic-ext/openapi/basics)
  using the v3.0 OpenAPI specification.

### Sanic Pros and Cons

**Pros**

- **High Performance**: Asynchronous capabilities make it very fast.
- **Async/Await Syntax**: Modern Python async support.

**Cons**

- **Smaller Ecosystem**: Fewer extensions and community support compared to
  larger frameworks.
- **Less Mature**: Not as battle-tested as some alternatives.

## 7. Falcon

### What is Falcon?

[Falcon](https://falcon.readthedocs.io/en/stable/) is a minimalist WSGI library
for building speedy web APIs and app backends.

### Falcon OpenAPI/Swagger Support

- **Extensions Required**: Libraries like
  [`falcon-openapi`](https://github.com/StoicPerlman/falcon-openapi) or
  [`falcon-apispec`](https://github.com/alysivji/falcon-apispec) enable OpenAPI
  support. It's worth noting that it's been many years since either of these
  extensions have been updated.
- **Manual Integration**: May require more hands-on setup to integrate OpenAPI.

### Falcon Pros and Cons

**Pros**

- **Performance**: Highly optimized for speed.
- **Lightweight**: Minimalistic design with few dependencies.

**Cons**

- **Less Out-of-the-Box Features**: Requires additional work for features like
  authentication.
- **Smaller Community**: Fewer resources and extensions.

## 8. Hug

### What is Hug

[Hug](https://hugapi.github.io/hug/) is a Python 3 framework that allows you to
develop APIs as simple as possible, but no simpler.

### Hug OpenAPI/Swagger Support

- **Built-in Support**: Automatically generates documentation and OpenAPI
  schemas from your code annotations. Unfortunately this is not in the OpenAPI
  or Swagger formats, so you will need to transform it yourself. I created a
  [simple script](https://gist.github.com/AdrianMachado/c7678a5cedf2c3f0e899042c10acc91c)
  to help you get started.

### Hug Pros and Cons

**Pros**

- **Simplicity**: Minimal setup with clean syntax.
- **Multiple Interfaces**: Can expose APIs over HTTP, CLI, or local functions.

**Cons**

- **Community Size**: Smaller user base, which may impact support.
- **Development Activity**: Less frequent updates compared to more popular
  frameworks.

## 9. Bottle

### What is Bottle?

[Bottle](https://bottlepy.org/docs/dev/) is a fast, simple, and lightweight WSGI
micro web-framework for Python.

### Bottle OpenAPI/Swagger Support

- **Extensions Required**: Use
  [`bottle-swagger`](https://github.com/ampedandwired/bottle-swagger) or
  [`bottle-openapi-3`](https://github.com/cope-systems/bottle-openapi-3).
- **Manual Configuration**: Might require manual steps to document APIs.

### Bottle Pros and Cons

**Pros**

- **No Dependencies**: Single-file module with no external dependencies.
- **Lightweight**: Ideal for small applications and prototyping.

**Cons**

- **Limited Features**: Minimalist by design; lacks advanced features out of the
  box.
- **Smaller Ecosystem**: Fewer plugins and extensions.

## 10.Pyramid

![Python Pyramid](/media/posts/2024-11-04-top-20-python-api-frameworks-with-openapi/image-3.png)

### What is Pyramid?

[Pyramid](https://trypyramid.com/) is a small, fast, down-to-earth Python web
framework. It is designed to make creating web applications easier.

### Pyramid OpenAPI/Swagger Support

- **Extensions
  Required**:[`pyramid_openapi3`](https://github.com/Pylons/pyramid_openapi3) is
  the latest extension, while others use Yelp's
  [`pyramid_swagger`](https://github.com/Yelp/pyramid_swagger). If you use
  [`cornice`](https://cornice.readthedocs.io/en/latest/) to build APIs on top of
  Pyramid, you can use the
  [`cornice-swagger`](https://pypi.org/project/cornice-swagger/) extension to
  add OpenAPI support.

### Pyramid Pros and Cons

**Pros**

- **Flexibility**: Suitable for both small and large applications.
- **Security**: Strong emphasis on security practices.

**Cons**

- **Complexity**: Steeper learning curve.
- **Popularity**: Less mainstream compared to Django or Flask.

## 11. Molten (deprecated)

### What is Molten?

[Molten](https://moltenframework.com/) is a minimal, fast, and extensible
framework for building HTTP APIs in Python. The project was deprecated in
April 2024.

### Molten OpenAPI/Swagger Support

- **Built-in Support**:
  [Automatically generates OpenAPI documentation](https://moltenframework.com/guide.html#openapi-schemas)
  from route definitions.
- **Type Annotations**: Uses type hints for routing and validation.

### Molten Pros and Cons

**Pros**

- **Performance**: Optimized for speed.
- **Modern Features**: Supports dependency injection and type annotations.

**Cons**

- **Limited Adoption**: Smaller community and fewer resources.
- **Less Mature**: Not as widely used or tested.

## 12. BlackSheep

### What is BlackSheep?

[BlackSheep](https://www.neoteroi.dev/blacksheep/) is an asynchronous web
framework to build event-based web applications with Python.

### BlackSheep OpenAPI/Swagger Support

- **Built-in Support**: BlackSheep
  [implements automatic generation of OpenAPI documentation](https://www.neoteroi.dev/blacksheep/openapi/)
  for most common scenarios, and provides methods to enrich the documentation
  with details.

### BlackSheep Pros and Cons

**Pros**

- **Async Support**: Designed for modern asynchronous Python.
- **Performance**: High-performance routing and handling.

**Cons**

- **Community Size**: Smaller user base.
- **Documentation**: Less comprehensive documentation.

## 13. Quart

### What is Quart?

[Quart](https://quart.palletsprojects.com/en/latest/) is an ASGI web framework
based on Flask, aiming to provide Flask's ease of use with the added benefit of
async support.

### Quart OpenAPI/Swagger Support

- **Extensions Required**: Similar to Flask, relies on extensions for OpenAPI
  support. [`quart-schema`](https://pypi.org/project/quart-schema/) is a newer
  extension, with the other being the older
  [`quart-openapi`](https://github.com/factset/quart-openapi?tab=readme-ov-file).
- **Compatibility**: Can use many Flask extensions directly.

### Quart Pros and Cons

**Pros**

- **Async Support**: Full support for async and await.
- **Familiarity**: Similar API to Flask.

**Cons**

- **Extension Compatibility**: Not all Flask extensions are compatible.
- **Smaller Ecosystem**: Fewer Quart-specific resources.

## 14. Responder

### What is Responder?

[Responder](https://github.com/kennethreitz/responder) is a web framework for
Python that aims to bring the best of Flask, Falcon, and others into one.

### Responder OpenAPI/Swagger Support

- **Built-in Support**:
  [Automatically generates OpenAPI documentation](https://responder.kennethreitz.org/tour.html#openapi-schema-support).
- **Interactive Documentation**: Provides Swagger UI.

### Responder Pros and Cons

**Pros**

- **Simplicity**: Easy to learn and use.
- **Automatic Documentation**: Reduces overhead in maintaining API docs.

**Cons**

- **Maintenance Status**: As of 2023, it is less actively maintained.
- **Community Size**: Smaller user base and fewer resources.

## 15. Tornado

### What is Tornado?

[Tornado](https://www.tornadoweb.org/en/stable/) is a Python web framework and
asynchronous networking library.

### Tornado OpenAPI/Swagger Support

- **Extensions Required**: Use
  [`tornado-swagger`](https://github.com/mrk-andreev/tornado-swagger) or similar
  libraries.
- **Manual Setup**: May require additional effort to integrate.

### Tornado Pros and Cons

**Pros**

- **Scalability**: Good for applications requiring long-lived connections.
- **Asynchronous**: Built-in async capabilities.

**Cons**

- **Less Conventional**: Different from standard WSGI frameworks.
- **Complexity**: May be more complex to work with.

## 16. Robyn

![Robyn Python](/media/posts/2024-11-04-top-20-python-api-frameworks-with-openapi/image-4.png)

### What is Robyn

[Robyn](https://robyn.tech/) is a high-performance, async Python web framework
with a focus on speed and efficiency. It leverages Rust's Tokio runtime via PyO3
to achieve impressive performance metrics. Robyn aims to be one of the fastest
Python web frameworks available.

### OpenAPI/Swagger Support

- **Built-in Support**: Robyn has
  [OpenAPI support built-in](https://robyn.tech/documentation/en/example_app/openapi),
  with both the spec on `/openapi.json` and documentation UI on `/docs`.

### Robyn Pros and Cons

**Pros**

- **High Performance**: Utilizing Rust's async runtime provides significant
  speed advantages.
- **Asynchronous**: Built with async and await syntax for modern Python
  development.
- **Minimalistic**: Lightweight framework that avoids unnecessary overhead.

**Cons**

- **Maturity**: Being relatively new, it may lack features and stability
  compared to more established frameworks.
- **Community Support**: Smaller community means fewer resources, plugins, and
  third-party extensions.
- **Documentation**: May have less comprehensive documentation due to its newer
  status.

## 17. Uvicorn

### What is Uvicorn?

[Uvicorn](https://www.uvicorn.org/) is a lightning-fast ASGI server
implementation, using `uvloop` and `httptools`. It is designed to run
asynchronous Python web applications, particularly those built with frameworks
like FastAPI, Starlette, and others.

### Uvicorn OpenAPI/Swagger Support

- **Not a Framework**: Uvicorn is an ASGI server, not a web framework. It
  doesn't provide features like routing, middleware, or OpenAPI support.
- **Usage with Frameworks**: When used with frameworks like FastAPI or
  Starlette, Uvicorn serves the application, and the framework handles
  OpenAPI/Swagger support.

### Uvicorn Pros and Cons

**Pros**

- **High Performance**: Extremely fast due to the use of `uvloop` and
  `httptools`.
- **Standards-Compliant**: Implements the ASGI specification, ensuring
  compatibility with various frameworks.
- **Lightweight**: Minimal overhead and easy to deploy.

**Cons**

- **Not a Full Framework**: Doesn't include web framework features; you'll need
  to use it in conjunction with an ASGI-compatible framework.

## 18. Starlette

### What is Starlette?

[Starlette](https://www.starlette.io/) is a lightweight ASGI framework/toolkit,
ideal for building high-performance async services in Python. It provides the
essential components needed to build web applications, including routing,
middleware, sessions, and more.

### Starlette OpenAPI/Swagger Support

- **Built-in Support**: Starlette
  [supports generating API schemas](https://www.starlette.io/schemas/) by
  inspecting the routes on the application through `app.routes`, and using the
  docstrings or other attributes on the endpoints in order to determine a
  complete API schema.

### Starlette Pros and Cons

**Pros**

- **High Performance**: Designed for speed and efficiency, suitable for building
  performant APIs.
- **Asynchronous**: Fully supports async and await, leveraging modern Python
  features.
- **Modular Design**: Allows developers to pick and choose components as needed.

**Cons**

- **Minimalist**: Lacks some higher-level features out of the box, such as
  automatic OpenAPI documentation.
- **Learning Curve**: May be challenging for those new to async programming or
  who prefer batteries-included frameworks.

## 19. Litestar

![Litestar python](/media/posts/2024-11-04-top-20-python-api-frameworks-with-openapi/image-5.png)

### What is Litestar?

Litestar (formerly known as Starlite) is a newly developed ASGI framework
inspired by Starlette and FastAPI, aiming to provide a balance between
performance and ease of use.

### Litestar OpenAPI/Swagger Support

- **Built-in Support**: Litestar has
  [built-in OpenAPI schema generation](https://docs.litestar.dev/2/usage/openapi/index.html)
  and automatic documentation.
- **Interactive Documentation**: Provides Swagger UI and ReDoc out of the box.

### Litestar Pros and Cons

**Pros**

- **Performance**: Designed to be fast and efficient.
- **Ease of Use**: Simplifies API development with sensible defaults.
- **Modern Features**: Supports async/await, type annotations, and dependency
  injection.

**Cons**

- **Newness**: As a newer framework, it may have less community support and
  resources.
- **Evolving API**: Frequent updates might lead to breaking changes.

## 20. API Star (Deprecated)

### What is API Star?

[APIStar](https://docs.apistar.com/) was a framework for building web APIs with
OpenAPI support. The project was deprecated in February 2022.

### API Star OpenAPI/Swagger Support

- **Built-in Support**:
  [Used OpenAPI schemas](https://docs.apistar.com/api-documentation/) directly
  in code.

### API Star Pros and Cons

**Pros**

- **Strong Typing**: Emphasized type annotations.

**Cons**

- **Deprecated**: No longer maintained; not recommended for new projects.

## How to Pick a Python API Framework?

When choosing a framework with OpenAPI/Swagger support, consider the following:

- **Project Requirements**: The size and complexity of your project. It might be
  hard to find developers for niche frameworks, and difficult to train-up
  existing teammates on the new paradigms/concepts.
- **Community and Support**: Frameworks with larger communities tend to have
  more resources.
- **Performance Needs**: If high performance is crucial, consider asynchronous
  frameworks like FastAPI or Sanic.
- **Development Style**: Whether you prefer code-first or API-first/Spec-first
  development.

## What is the Best Python API Framework?

**FastAPI** stands out for its built-in OpenAPI support, high performance,
thriving community, and modern features. **Django REST Framework** is ideal if
you're already using Django and need a robust, feature-rich API framework.
**Flask** offers flexibility and simplicity but requires extensions for OpenAPI
support - so we don't recommend it for newer projects..

## What is the Fastest Python API Framework?

As of November 2024,
[Robyn claims](https://github.com/sparckles/robyn?tab=readme-ov-file#robyn) to
be the fastest framework:

![Fastest Python API Framework](/media/posts/2024-11-04-top-20-python-api-frameworks-with-openapi/image.png)

## Python API Essentials - Don't Forget These!

Regardless of which Python API framework you choose, you will need the
[3 pillars of APIs](/learning-center/the-three-pillars-of-an-api-program) before
you go to prod:

1. Authentication (ex. API Key Authentication)
2. Documentation (ex. Developer documentation portal with API reference, auth,
   billing, analytics, code samples, etc.)
3. Protection (ex. Rate limiting and quotas)

Zuplo can take care of all of these for you - for free! You can
[start for free](https://portal.zuplo.com/signup?utm_source=blog) or grab time
with our team and [see Zuplo in action](https://zuplo.com/meeting).

## Frequently Asked Questions

### What is WSGI?

WSGI stands for Web Server Gateway Interface. It is a specification that defines
a standard interface between web servers and Python web applications or
frameworks. WSGI allows developers to write portable web applications that can
run on any WSGI-compliant web server, promoting interoperability and flexibility
in the Python web ecosystem.

### What is ASGI?

ASGI stands for Asynchronous Server Gateway Interface. It is a specification
that defines a standard interface between asynchronous Python web servers,
frameworks, and applications. ASGI was developed as a successor to WSGI (Web
Server Gateway Interface) to support asynchronous, event-driven applications and
protocols beyond HTTP, such as WebSockets.

### What are the Differences Between WSGI and ASGI

<table>
  <thead>
    <tr>
      <th>Feature</th>
      <th>WSGI</th>
      <th>ASGI</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Concurrency</td>
      <td>Synchronous (one request at a time)</td>
      <td>Asynchronous (handles multiple connections concurrently)</td>
    </tr>
    <tr>
      <td>Protocols</td>
      <td>HTTP/1.1 only</td>
      <td>HTTP/1.1, HTTP/2, WebSockets, and more</td>
    </tr>
    <tr>
      <td>Use Cases</td>
      <td>Traditional web applications</td>
      <td>Real-time apps, long-lived connections, async services</td>
    </tr>
    <tr>
      <td>Python Versions</td>
      <td>Compatible with older Python versions</td>
      <td>Requires Python 3.5+ for async features</td>
    </tr>
  </tbody>
</table>

### Where Should I Host my Python API?

There are many options for hosting your Python API including

- Platform as a Service (PaaS) providers like PythonAnywhere or Render
- Infrastructure as a Service (IaaS) aka big clouds like AWS EC2, Azure VM, GCP
  Compute Engine
- Virtual Private Servers (VPS) like DigitalOCean or Linode
- Containers (Docker + Kubernetes) using Google Kubernetes Engine
- Serverless Platforms like AWS Lambda or Google Cloud Functions

### What is the Best API Gateway for Python APIs?

Zuplo's edge API gateway provides superior caching performance, an intuitive
developer experience using git, and
[full OpenAPI support](https://zuplo.com/features/open-api). This makes it a
natural choice for most Python API frameworks, especially the ones with OpenAPI
support.

### What is the Best Way to Document a Python API?

Many Python frameworks (ex. FastAPI, Litestar) have built-in support for
OpenAPI, which most API documentation platforms (ex. Zudoku) support
out-of-the-box. For a complete API documentation experience, consider Zuplo's
[Developer Portal](https://zuplo.com/features/developer-portal) - which features
docs, built-in authentication, self-serve billing, and usage analytics.