Jonathan Bowman

Top 1 Python Web Frameworks to Learn in the 21 th Century

Categories: Python

Top 1 Python Web Frameworks to Learn in the 21 th Century

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:

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:

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

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

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:

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

Automate the Boring Stuff with Python

The Hitchhiker’s Guide to Python

The Hitchhiker’s Guide to Python

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

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

Also worth mentioning:

I want to build an API

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 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

Are you one of those GraphQL hipsters? Good for you. Thankfully, Graphene-Python 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, Github Pages, or Gitlab Pages.

Pelican

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

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

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:

You can build a basic WSGI app with nothing more than the Python standard library. There is even an example in the docs.

If you want to pursue the asynchronous route, you may appreciate my article on building your own simple ASGI app. To run an ASGI app, you will want to use one of the three excellent ASGI servers.

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. 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.