Top 13 Python web frameworks to learn in 2023
In this article, we share a list of the top twelve Python web frameworks that will be useful on your way to becoming a professional backend developer and improving your existing skill set.
Why Python frameworks? Stack Overflow has recently released the results of their annual developer survey for 2022, which declared Python the fastest-growing major programming language.
Source: stackoverflow.blog
By far, the most popular Python frameworks are Django and Flask. But that doesn’t mean you should discount the potential of other frameworks. Each of them possesses features that could be a perfect match for your web project.
Source: jetbrains.com
Keep in mind that the Python frameworks we’re going to talk about here are not listed in any particular order: we’ve focused on showing what you’re able to do as opposed to telling you what you should do.
Some things to consider
For one thing, when deciding which framework to use, look at the size and complexity of your project. If what you’re looking to develop is a large system packed with features and requirements, a full-stack framework might be the right choice. If your app is on the smaller and simpler side, you should probably consider a microframework.
Second, you need to check if the framework you’re considering can scale vertically and horizontally. This is a must for projects that are to run on several servers, handle huge amounts of traffic, and support the addition of new features to enhance functionality.
Once you’ve chosen a framework, contact a team of developers and ask them for information about the estimated cost to develop your app.
You can find information about the type and focus of some frameworks here. A final decision, though, should come from your own understanding of your project and the tasks you want to simplify.
However, frameworks can also stand in the way of development. When choosing a full-stack framework, you’re often signing up for a set of limitations. Of course, you can find ways to work around them, but be careful you don’t spend more time fighting for your own freedom than you would have writing an app in pure Python.
Full-stack frameworks
A full-stack framework or an enterprise framework is an all-in-one solution with libraries configured to work seamlessly together. It supports the development of backend services, frontend interfaces, and databases. A full-stack framework provides anything a developer requires for building an application. Python offers more than one full-stack framework.
Django
Official Website | GitHub | PyPI
GitHub Stars: 75.7k | GitHub Forks: 30.4k
Django is a free open-source full-stack Python framework. It tries to include all of the necessary features by default as opposed to offering them as separate libraries.
Some of the exemplary features of Django are its authentication, URL routing, template engine, object-relational mapper (ORM), and database schema migrations (Django v.1.7+).
These features make Django highly scalable, ridiculously fast, and extremely versatile.
Django uses its ORM to map objects to database tables. The same code works with different databases and isn’t difficult to transfer from one database to another. The main databases that Django works with are PostgreSQL, MySQL, SQLite, and Oracle, but third-party drivers allow you to use others as well.
With Django, you can craft any web application from small-scale projects to complex websites. Thanks to its flexibility, Django is also used for crafting MVPs, allowing startups to optimize their time and budget.
Django’s user base is expected to grow, as many developers see this framework as the best choice for emerging technologies such as machine learning. Also, in 2020, the Django community is planning to release more libraries to meet the growing demand.
Here at Globaldev, we use Django as our primary framework for backend development. If you’d like to see the amazing apps we’ve already developed with Django, visit our case study page.
Pyramid
Official Website | GitHub | PyPI | Awesome
GitHub Stars: 3.9k | GitHub Forks: 876
Pyramid is an open-source – and the second noteworthy – Python-based web application framework. Its goal is to do as much as possible with minimum complexity. Running on Python 3, Pyramid keeps up with technological improvements. Pyramid 1.10 is the current version of the framework and is the tenth update since 2010.
The most striking feature of Pyramid is its ability to work well with both small and large applications. Some of Pyramid’s great features include:
- Single-file applications
- URL generation
- Extensible configuration
- All-embracing templating and asset specifications
- Flexible authentication and authorization
- Testing, support, and comprehensive data documentation
- View predicates and many per-route views
- Function decorators
- Predicates
- Renderers
With Pyramid, a developer can decide on the templating language, generation libraries, and database layer.
The Pyramid community is active and boasts many releases. Developers can follow the framework’s progress by joining the official IRC channel or joining Google and Twitter groups.
TurboGears
Official Website | GitHub | PyPI
GitHub Stars: 798 | GitHub Forks: 77
TurboGears is an open-source, data-driven full-stack web application framework. It’s built on lots of middleware and many libraries and was initially crafted to combine the best components of other Python frameworks.
TurboGears allows you to quickly develop extensible data-driven web applications. It comes with a user-friendly templating engine and a powerful and flexible ORM. In addition to great template systems that make designers’ lives easier, TurboGears offers lots of flexibility, strong support of aggregates, a powerful ORM, and reusable snippets.
Some of TurboGears’ distinctive features include:
- Multi-database support
- MVC-style architecture
- Support for SQLObject and SQLAlchemy
- Kid and Genshi included in preferred templating languages
- Validation with FormEncode
- Pylons as a web server
- ToscaWidgets, an application library that simplifies coordination of frontend design and server development
- PasteScript templates
- Front-facing WSGI-based servers (Paste HTTP server, CherryPy WSGI/HTTP server, etc.)
- Command-line tools
- MochiKit JavaScript library integration
- All features implemented as function decorators
As for the future of TurboGears, the community is currently working on improving the framework’s capabilities and overall stability and are about to release the “minimal code.” This code is also referred to as a microframework, or a stripped-down version of TurboGears. The minimal code will help developers build apps faster, saving money and time.
Web2py
Official Website | GitHub | PyPI
GitHub Stars: 2.1k | GitHub Forks: 893
Web2py is a scalable open-source full-stack Python framework. It’s very powerful when it comes to handling data. Web2py was originally offered as a teaching tool with a focus on ease of use. This explains why there are no project-level configuration files.
What’s great about Web2py, though, is that it comes with its own web-based IDE which, among other things, includes a code editor, debugger, and one-click deployment.
Other valuable Web2py features include:
- No requirements for installation and configuration
- Ability to run on Windows, Mac, Linux/Unix, Google App Engine, Amazon EC2, and any web hosting that supports either Python 2.5–2.7 or Java+Python
- Readability of multiple protocols
- Data security that prevents such vulnerabilities as cross-site scripting, injection flaws, and malicious file execution
- Successful employment of software engineering practices, making code easy to read and maintain
- Error tracking, thorough error logging and ticketing
- Role-based access control
- Support for internationalization
- Backward compatibility that ensures user-oriented advancement without the need to lose ties with earlier versions
A ticketing system is the main feature of Web2py; it issues tickets whenever errors occur. This way, users can track errors and their statuses.
Despite all these advantages, the Web2py community is smaller than Pyramid’s or Django’s. Not many developers are using it. This means the chances of receiving support are lower. Plus, the official mailing list is not very active.
Microframeworks
A microframework, or a minimalistic web application framework, lacks most of the functionality of a full-fledged framework such as a web template engine, authentication functionality, accounts, authorization, input validation, and input sanitation. A microframework attempts to provide only the component set required for building an application. It may also focus on providing the necessary functionality for one particular sphere.
Flask
Official Website | GitHub | PyPI | Awesome
Github Stars: 65.8k | GitHub Forks: 15.9k
Flask is a Python framework available under the BSD license. It was inspired by the Sinatra Ruby framework. Flask depends on the Werkzeug WSGI toolkit and Jinja2 template.
The main idea behind Flask is to help build a solid web application foundation. From there, you can use any extensions you might need. Flask is chosen for any and all projects. In fact, it’s a default choice for any web project that isn’t a match for Django.
Flask’s lightweight and modular design makes it easily adaptable to developers’ needs. It includes a number of useful out-of-the-box features:
- Built-in development server and a fast debugger
- Integrated support for unit testing
- RESTful request dispatching
- Jinja2 templating
- Secure cookies support (client-side sessions)
- WSGI 1.0 compliance
- Unicode-based
- Ability to plug in any ORM
- HTTP request handling
Since its launch in 2010, Flask has been updated 27 times. To date, it remains the top growing Python framework. However, many Flask extensions are no longer supported: the documentation is outdated and they’re no longer being developed. If you run into this, you’ll need to Google to find an actively supported plug-in with similar functionality.
Bottle
Official Website | GitHub | PyPI
GitHub Stars: 8.2k | GitHub Forks: 1.5k
Bottle is a microframework. Originally meant for building APIs, Bottle implements everything in a single source file. It has no dependencies apart from the Python Standard Library. Coding with Bottle gets you closer to the metal than coding with any full-stack framework. However, Bottle is a match only if you’re crafting a very small application with at most 500 lines of code and no special requirements.
Its default features include routing, templating, utilities, and a basic abstraction over the WSGI standard.
- Routing – supports requests to function-call mapping, allowing you to achieve clean and dynamic URLs
- Templates – a fast and Pythonic template engine out of the box along with full support for mako, jinja2, and cheetah
- Utilities – comfortable access to form data, file uploads, cookies, headers, and other HTTP-related metadata
- Server – a built-in HTTP development server that supports fapws3, bjoern, GAE, СherryPy, and any other WSGI-capable HTTP server
Since 2009, Bottle has been updated 73 times, and now it’s a perfect solution for prototyping, learning the organization of web frameworks, and building simple personal apps.
Any contributions to the Bottle community are accepted via GitHub. Users can also join the Bottle mailing list and blog and follow the latest changes on Twitter. If you’re looking for an additional forum for discussion, join a freenode chat.
CherryPy
Official Website | GitHub | PyPI
GitHub Stars: 1.8k | GitHub Forks: 361
CherryPy is an open-source, minimalist web framework. It makes building Python web applications no different than building any other object-oriented program.
CherryPy is created to be extensible. The framework even offers mechanisms for hook points and extensions.For example, a CherryPy-powered web app is a standalone Python application that embeds its own multi-threaded web server. With its own web server, the extension points include functions outside the request-response cycle, thus adding to the level of CherryPy’s extensibility.
In fact, a CherryPy-powered web app is a standalone Python application that embeds its own multi-threaded web server. CherryPy apps run on any operating system that supports Python (Windows, macOS, Linux, etc.). They can be deployed anywhere you can run an ordinary Python app. You don’t need Apache for CherryPy apps, but you can run a CherryPy app behind Apache just as well as you can run it behind Lighttpd or IIS.
CherryPy isn’t a very limiting framework, as it allows you to use any type of technology for templating, data access, and so on. However, it’s still able to handle sessions, statics, cookies, file uploads, and everything else that a web framework typically can.
Some of the default CherryPy features include:
- An HTTP/1.1-compliant WSGI thread-pooled webserver
- Simplicity of running multiple HTTP servers at once
- A powerful configuration system
- A flexible plugin system
- Out-of-the-box tools for caching, encoding, sessions, authentication, static content, and so on
- Built-in support for profiling, coverage, and testing
- Ability to run on Python 2.7+, Python 3.1+, PyPy, Jython, and Android
Despite all its features and advantages, many developers feel that CherryPy’s documentation could use some improvement. Plus, CherryPy could be at least a bit easier to use.
Like most other frameworks, CherryPy has a community behind it that provides assistance to beginners and advanced developers. CherryPy has a mailing list and suggests developers join the framework’s IRC channel or Gitter and Google groups.
Falcon
Official Website | GitHub | PyPI
GitHub Stars: 9.3k | GitHub Forks: 914
Falcon is a bare-metal Python web API framework for building very fast app backends. The logo of the framework is a falcon, symbolizing how quickly Falcon works.
This framework allows developers to craft cleaner designs and handles most requests. Falcon never restricts developers in choosing libraries for databases and authorization.
Other valuable Falcon features:
- 100% code coverage with a comprehensive test suite
- A highly optimized code base
- Upfront exception handling
- REST-inspired resource classes
- URI templates for intuitive routines
- Easy access via request and response classes
- DRY request processing via middleware components
- Idiomatic HTTP error responses
- Unit testing via WSGI helpers
Falcon ignores useless operations during the development of a web framework. Also, it gives freedom of choice: developers can make decisions that will help them tune and customize implementations freely.
Two more advantages worth mentioning are the availability of extensive documentation and an active community.
Hug
Official Website | GitHub | PyPI
GitHub Stars: 6.8k | GitHub Forks: 395
Hug is a Python 3 API development framework. It’s crafted to allow software engineers to develop an API once and then reuse it whenever needed. The Hug framework simplifies API development by offering various interfaces. That’s the main reason why this framework is called one of the fastest in Python 3.
Key features of Hug:
- Support for automatic documentation
- Annotation-powered validation
- Built-in version management
- Compliance with Cython
- Can be used as a Python library
The Hug framework contains as few integrations and as little code as possible, remaining functional and providing great performance. Plus, Hug’s community is currently growing. That’s a sign of the framework's demand and proof that whenever a problem occurs, a developer can find help.
FastAPI
Official Website | GitHub | PyPI
GitHub Stars: 68.4k | GitHub Forks: 5.7k
FastAPI is a modern Python-based framework. It was initially designed to be easy to use for ensuring the best development experience. To date, FastAPI is one of the fastest frameworks for building APIs with Python 3.6+.
The framework took several characteristics from Flask, including its simplicity. The whole framework is built on Starlette and includes most of its features (templates, WebSockets, and GraphQL support).
The FastAPI framework offers:
- Increase in development speed by 200% to 300%
- Reduced errors by 40%
- Less time debugging
- Minimization of code duplication
- Automatic interactive documentation
FastAPI isn’t tightly coupled to any database. However, it supports databases you need. With FastAPI, you are free to structure your project the way you need and even use most of the same files from one of your Flask projects.
The only drawback is its small community. But it’s because FastAPI is a relatively new framework.
Asynchronous frameworks
An asynchronous framework is a relatively recent type of Python framework. It’s a microframework that enables developers to handle a large set of concurrent connections. Asynchronous frameworks use non-blocking sockets and feed on Python’s asyncio library.
Sanic
Official Website | GitHub | PyPI
GitHub Stars: 17.6k | GitHub Forks: 1.6k
Sanic is a Python web framework built on uvloop and created specifically for fast HTTP responses via asynchronous request handling.
It runs on Python 3.5+. Sanic supports asynchronous request handlers, which makes it compatible with Python 3.5’s async/await functions. This enhances its speed, offering non-blocking capabilities.
Sonic is considered the preferred asynchronous framework in the Python world due to its routing, middleware, cookies, versioning, static files, blueprints, class-based views, and sockets. However, it doesn’t offer database support and templating.
In a benchmark test with one process and 100 connections, Sanic was able to handle 33,342 requests per second, with an average latency of 2.96 ms.
Tornado
Official Website | GitHub | PyPI
GitHub Stars: 21.4k | GitHub Forks: 5.6k
Tornado is a Python web framework and asynchronous networking library that focuses on speed and the ability to handle large volumes of traffic.It uses a non-blocking network I/O and solves the C10k issue (meaning that, if configured properly, it can handle 10,000+ concurrent connections).
This makes it a great tool for building applications requiring high performance and tens of thousands of concurrent users.
Tornado’s main features are:
- Built-in support for user authentication
- Real-time services
- High-quality performance
- Python-based web templating language
- Non-blocking HTTP client
- Implementation of third-party authentication and authorization schemes (Google OpenID/OAuth, Facebook Login, Yahoo BBAuth, FriendFeed OpenID/OAuth, Twitter OAuth)
- Support for translation and localization
In terms of popularity, Tornado stands somewhere between Django and Flask. Say you want to write something in Flask or Django because of their features and tools, but you also need much better performance. In this case, you should choose Tornado.
Other
Dash
Official Website | GitHub | PyPI | Awesome
GitHub Stars: 20.1k | GitHub Forks: 2k
Dash is an open-source Python framework used for building analytical web applications. It’s especially good for Python data scientists who aren’t very familiar with web development.
There are two basic benefits of Dash:
- It allows you to build highly interactive applications using only Python code.
- It makes it simple to use the power of Python tools for manipulating data.
Dash applications are web servers that run Flask and communicate with JSON packets over HTTP requests. Their frontend renders components with React.js.
Apps developed with Dash are rendered in the web browser and can be deployed to servers. This also means that Dash applications are inherently cross-platform and mobile-ready.
Dash developers have access to the underlying Flask instance and all of its configurable properties. To extend the capabilities of Dash applications, developers can also use the rich set of Flask Plugins.
Choosing a Python web framework
The right framework might be all you need to develop a successful project. We really hope that you’ve found an interesting framework in this article. Our Product Engineering teams are trying hard to innovate in the world of tech, and the more people who get involved, the better.