A few days ago, a friend left me a message saying: When will there be a useful summary of the Python framework (the list in this article is only a part, and does not include all Python frameworks), so today's article was born. (Suddenly I feel very nice)
Recommended one: Django (Recommended learning: Python video tutorial)
Django should be the most famous Python framework, GAE and even Erlang have frameworks affected by it. Django is taking a big and comprehensive direction. It is most famous for its fully automated management backend: just use the ORM and make simple object definitions, and it can automatically generate a database structure and a full-featured management backend.
Advantages:
Open source framework, with perfect documentation support
Many solutions, more internal function support
Elegant URL, complete routing System
Self-service background management
Disadvantages:
The system is tightly coupled, and it is very difficult to replace it with your favorite third-party library, even with some patches. It will also feel very awkward when you get on it.
The ORM that comes with Django is far less powerful than SQLAlchemy.
Template function is relatively weak and cannot insert Python code. To write more complex logic, you need to use Python to implement Tag or Filter.
Recommendation 2: Flask
Flask is a lightweight web application framework written in Python. Based on Werkzeug WSGI toolbox and Jinja2 template engine. Flask is also called a "microframework" because it uses a simple core and uses extensions to add additional functionality. Flask does not have a database or form validation tool used by default.
Advantages:
Flask is more flexible than Django. Before using Flask to build an application, it will give developers more flexibility when selecting components. Some application scenarios may not be suitable. Use a standard ORM (Object-Relational Mapping), or need to interact with different workflow and template systems.
Disadvantages:
Flask is just a kernel and relies on two external libraries by default: Jinja2 template engine and Werkzeug WSGI tool set. Many other functions are embedded in the form of extensions.
Recommendation 3: Scrapy
Scrapy is a fast, high-level screen scraping and web scraping framework developed in Python, used to scrape web sites and extract them from Extract structured data from the page. Scrapy is widely used and can be used for data mining, monitoring and automated testing.
Advantages:
Scrapy is a very powerful crawler framework. It can not only easily construct requests, but also has a powerful selector that can easily parse responses. However, its most popular Its performance includes the speed of crawling and parsing, its downloader is multi-threaded, and requests are scheduled and processed asynchronously. These two points make its crawling speed very fast.
In addition, there are built-in logging, exception, shell and other modules, which bring a lot of convenience to crawling work.
Disadvantages:
Scrapy is an encapsulated framework. It includes a downloader, parser, log and exception handling. It is based on multi-threading and twisted processing. For crawling a single website, It has advantages in development, but for crawling 100 websites from multiple websites, it is not flexible enough in terms of concurrent and distributed processing, and it is inconvenient to adjust and expand.
Recommendation 4: Tornado
Tornado is an open source version of web server software. There is a clear difference between Tornado and today's mainstream web server frameworks (including most Python frameworks): it is a non-blocking server and quite fast.
Advantages:
Tornado excels at providing infrastructure for applications that require tight control over the details of asynchronous networking. For example, Tornado not only provides a built-in asynchronous HTTP server, but also an asynchronous HTTP client. Therefore, Tornado is ideal for building applications, such as web scrapers or bots, that query other sites in parallel and operate on the returned data.
Disadvantages:
There are many third-party modules to choose from in the template and database parts, which is not conducive to encapsulation into a functional module.
Recommendation 5: Web2py
web2py is a full-featured Web application framework provided for the Python language. It is designed to develop Web applications agilely and quickly, with fast, safe and Portable database-driven application, compatible with Google App Engine.
Advantages:
The biggest attraction of Web2py is its built-in development environment. When you set up a Web2py instance, you are given a web interface, effectively an online Python application editor, where you can configure the components of your application. This usually means creating models, views, and controllers, each described through Python modules or HTML templates.
Disadvantages:
One important limitation of Web2py is that it is only compatible with Python 2.x. First this means that Web2py cannot use Python 3's asynchronous syntax. If you rely on external libraries that are unique to Python 3, you're out of luck. However, work is underway to make Web2py Python3 compatible and it is nearing completion at the time of writing.
Recommendation 6: Weppy
Weppy feels like the middle mark between the minimalist style of Flask and the completeness of Django. While developing Weppy applications has the directness of Flash, Weppy has many features found in Django, such as data layer and authentication. Therefore, Weppy is suitable for applications ranging from extremely simple to moderately complex.
Advantages:
Weppy’s documentation has the same style as the framework itself. It's clean, readable, and intended for human consumption. In addition to the usual "hello world" application examples, it also contains a good walkthrough tutorial that allows you to create a Weibo system as a beginner project.
Disadvantages:
Although Weppy has an extension mechanism, the list of officially approved add-ons is small, much smaller than Flask’s extension directory.
Recommendation 7: Bottle
Bottle can be considered a mini-flask because it is more compact and concise than other "micro-frameworks". Due to its minimal footprint, Bottle is ideal for inclusion in other projects or for quick delivery of small projects such as REST APIs.
Advantages:
Bottle does not require as much documentation as other frameworks, but the documentation is by no means stingy. All the key stuff fits into a single (albeit long) web page. In addition to this, you'll find full documentation for each API, examples of how to deploy on various infrastructures, explanations of the built-in templating language, and a collection of common recipes.
Disadvantages:
One consequence of Bottle’s minimalism is that some features simply don’t exist. Form validation, including CSRF protection and other features, is not supported. If you want to build a web application that supports a high degree of user interaction, you will need to add them yourself.
For more Python related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of What frameworks are available in python?. For more information, please follow other related articles on the PHP Chinese website!