Top 1 Python Web Frameworks to Learn in the 21 th Century
Tags: python, webdev
Published: 2020-09-13 13:26:32

There are many [Python] web frameworks. Most of them are quite good. You could probably write one yourself, as many have.

Yet you probably only need to know about one, maybe two.

You don't need the top 20 or even the top five, or the ones that are trending this year. You need one that works well _for you_, has good documentation and community support, and is kept reasonably up to date.

This article is for those exploring [Python] web development, who simply want to get started on their next project, trying out a Python web framework with which they were previously unfamiliar. It is intended to help you identify who you are, your desires, and pair you with a well-documented path forward.

This article _is not_:

- going to recommend the one perfect framework that beats all the rest. Such a creature does not exist.
- a comprehensive overview of all, or even most, Python web frameworks.
- necessarily going to include your favorite Python web framework, if you have already explored the landscape. Please know that you, and the framework you chose, are still awesome. Keep using the treasure you have found.
- a comparison of framework performance, or security, or trendiness.
- going to explain how Python is better than [Node], [Go], [Rust], or [.NET][dotnet]. It isn't better, and neither are they.

If you need any of the above, there are great resources out there. Because Python and web development are such a good match, searching the web for such topics is a rewarding endeavor.

## Who are you? What do you want?

Your next web development project in Python will be most satisfying after spending just a few moments in introspection. You might consider these questions:

- Do you prefer using tools that are all-inclusive, with everything you need, or do you prefer a modular approach, in which you start with a core, and then research and add features as needed? Put another way, do you want user authentication and RSS feeds included in your framework?
- Do you favor the satisfaction of the cutting edge, or the robust stability of tried-and-true?
- Are you new to Python or to programming in general?
- Do you know what an event loop is? In other words, do you come from [Node] or [Go] and want to explore similar patterns in Python?

These questions are just to get us started. The headings below ask similar and additional questions, followed by my recommendations.

## I just want to get started

[![Django](https://dev-to-uploads.s3.amazonaws.com/i/bclh45glyrhk3eaz1aml.png)][django]

Choose [Django]. It includes all you will likely need, and has exceptional documentation.

[![Flask](https://dev-to-uploads.s3.amazonaws.com/i/ktpsb0q338gkbuym4e1k.png)][flask]

Prefer a minimalist/modular approach? Choose [Flask]. Great community and documentation.

Better yet, take a quick glance at both [Flask] and [Django], then make a choice or flip a coin. You will not go wrong with either.

Also worth mentioning:

- [Bottle]: even more minimalist (just one file). Fast and fun. One of my favorites.
- [Pyramid]: not micro or mega. Somewhere in between. Not nearly as popular as the others mentioned, but has good history and makes good choices

## I am learning Python, or learning to program

Oh, so many good resources. I will recommend two books that you can read for free online, or buy in print:

[Automate the Boring Stuff with Python][boring]

[![Automate the Boring Stuff with Python](https://automatetheboringstuff.com/images/automate_2e_cover.png)][boring]

[The Hitchhiker's Guide to Python][hitchhiker]

[![The Hitchhiker's Guide to Python](https://d33wubrfki0l68.cloudfront.net/7b1098a979f88fe7168ab273be04a96c85dd7702/2c5e5/_static/guide-book-cover.jpg)][hitchhiker]

These are not just about web development, but are great introductions to Python.

That said, there is no shame in diving right in, if you love the sink-or-swim approach. If so, choose [Django] or [Flask] and proceed with passion.

## I heard of this thing called asyncio...

Single threaded concurrency, event loops, async/await, oh my...

This is not a good starting place. But if you have some experience with Python, and/or with event loops (coming from [Go] or [Node], for instance), or you just want to try the cutting edge, this is a good place to be.

> If you just wanted the fastest Python web framework out there, this is not the right choice. Even though it is, arguably, where the fastest Python web frameworks are. I just don't think speed should be the only reason to explore Python [asyncio].

[![Starlette](https://dev-to-uploads.s3.amazonaws.com/i/238dabj24c7fx20cevad.png)][starlette]

Choose [Starlette]. Enough features, growing community and documentation, great technology.

Want something that has been around longer and earned its place over and over (and even includes an HTTP client, not just a server)? [AIOHTTP] is well designed, solid, and current.

[![AIOHTTP](https://dev-to-uploads.s3.amazonaws.com/i/px2bojoypoa516tz25qg.png)][aiohttp]

Also worth mentioning:

- [Django has async support](https://docs.djangoproject.com/en/3.1/topics/async/)
- [FastAPI] is built on [Starlette] and designed for building APIs
- [Quart] tries to be just like [Flask], but with async support
- [Sanic] is very popular
- [Tornado] was async before async was cool

## I want to build an API

[![Falcon](https://dev-to-uploads.s3.amazonaws.com/i/b446cshkn4pungb8zj16.png)][falcon]

[Falcon] is a great framework for getting a REST API framework built fast and running fast.

If you love the everything-and-the-kitchen-sink approach of [Django], then the [Django REST Framework][djangorest] is an add-on worth a look, and has a great community around it.

If you prefer the async approach mentioned earlier, then [FastAPI] is the right choice. There is a lot of love for that framework, built on [Starlette].

[![FastAPI](https://dev-to-uploads.s3.amazonaws.com/i/lviylymdx86vbt4yomqy.png)][fastapi]

Are you one of those GraphQL hipsters? Good for you. Thankfully, [Graphene-Python](https://graphene-python.org/) is a library that can be paired with any of the above.

## I just want to build a blog

Any Python framework can be used to build a blog. But if you just want to start writing posts, with the reassurance that your blog engine has Python under the hood, then may I suggest that a static site generator may work well for you? Typically, you write in Markdown, generate the HTML, and post to your favorite web hosting, such as [Netlify](https://www.netlify.com/), [Github Pages](https://pages.github.com/), or [Gitlab Pages](https://docs.gitlab.com/ee/user/project/pages/).

[![Pelican](https://dev-to-uploads.s3.amazonaws.com/i/xos72ziynwf6bsmue000.png)][pelican]

Use [Pelican]. It is solid and mature, and can import themes from Wordpress.

[![Lektor](https://www.getlektor.com/logo.png)][lektor]

[Lektor] and [Cactus] also deserve a look.

If you are primarily writing documentation, [MkDocs] is easy, pretty, and popular.

## We don't need no stinkin' frameworks (DIY, roll-your-own approach)

![Invent the wheel](https://dev-to-uploads.s3.amazonaws.com/i/9gcnb3kjmnlnnzs5oq56.jpg)

For some of us, re-inventing the wheel is way better than accepting someone else's design approach.

If this is you, then you will want to be familiar with at least one of the following interfaces:

- [WSGI](https://docs.python.org/3/library/wsgiref.html), the standard interface for Python web apps
- [ASGI](https://asgi.readthedocs.io/), a newer standard for async interfaces

You can build a basic WSGI app with nothing more than the Python standard library. There is even [an example in the docs](https://docs.python.org/3/library/wsgiref.html#examples).

If you want to pursue the asynchronous route, you may appreciate [my article on building your own simple ASGI app](https://dev.to/bowmanjd/write-your-own-python-async-asgi-app-no-framework-needed-1296). To run an ASGI app, you will want to use one of [the three excellent ASGI servers](https://dev.to/bowmanjd/the-three-python-asgi-servers-5447).

If you try to make your own, you will quickly discover why there are so many Python web frameworks. It is remarkably easy and rewarding.

## Keeping up?

You will likely be quite happy with any of the frameworks mentioned in this article. There is no need to worry that the one you are using is antiquated, insecure, or slow, as they are all kept up to date, and you really should be the judge of performance, not some theoretical benchmarks. In other words, its not slow unless it feels slow.

That said, if you like to keep your eyes on the landscape, you may appreciate my method: I periodically check [Techempower's benchmarks](https://www.techempower.com/benchmarks/). Expand the filters, select "Disable all" on Language, then select Python, and "Apply changes." To me, the performance is interesting, but shouldn't be overemphasized. What is interesting is the list, as it shows all major Python web frameworks, as well as a few up-and-coming. Regarding the new ones, take a look on Github to see how many maintainers they have, and how often the code is updated. They may be fast, but that doesn't mean they will be around two years from now.

Keeping up should only be a hobby on the side, if you find it enjoyable. You only need, at most, two frameworks: the one you are using now, and the one you are using next.

[aiohttp]: https://docs.aiohttp.org/
[asyncio]: https://docs.python.org/3/library/asyncio.html
[boring]: https://automatetheboringstuff.com/
[bottle]: https://bottlepy.org/
[cactus]: https://github.com/eudicots/Cactus
[django]: https://www.djangoproject.com/
[djangorest]: https://www.django-rest-framework.org/
[dotnet]: https://dotnet.microsoft.com/
[falcon]: https://falcon.readthedocs.io/
[fastapi]: https://fastapi.tiangolo.com/
[flask]: https://flask.palletsprojects.com/
[go]: https://golang.org/
[hitchhiker]: https://docs.python-guide.org/
[lektor]: https://www.getlektor.com/
[mkdocs]: https://www.mkdocs.org/
[node]: https://nodejs.org/
[pelican]: https://docs.getpelican.com/
[pyramid]: https://trypyramid.com/
[python]: https://www.python.org/
[quart]: https://pgjones.gitlab.io/quart/
[rust]: https://www.rust-lang.org/
[sanic]: https://sanicframework.org/
[starlette]: https://www.starlette.io/
[tornado]: https://www.tornadoweb.org/