跳转至

2018 年排名前 11 的 Python 框架

Python is an interpreted, dynamically-typed, and high-level language. It also implements the basic concepts of an object-oriented programming language (OOP). It has a unique syntax, which makes it different from other programming languages such as Java, C++, and C. Hence, it is simple and easy to learn the language.

Most developers use frameworks to create code and develop applications. The framework provides a defined structure to the developers so that they can focus on the core logic of the application rather than on other elements.

In order to start development with Python, you will require a platform or framework to code. While choosing a framework, remember to consider the size and complexity of your application or project. In this article, we will discuss some commonly used Python frameworks.

Python provides support for a wide range of frameworks. Generally, there are two types of Python framework used while developing applications.

Python Frameworks

全栈框架

全栈框架为开发人员提供了完整的支持,包括表单验证,表单生成器和模板布局等必要元素。 一些常见的全栈框架是:

1. Django

Django 由 Django Software Foundation 开发,是一个全栈 Python Web 框架。 It is an open source and free-to-use framework, released officially in July 2005. It helps developers to create complex code and applications in an easier way, and requires much less time compared to other frameworks. It follows the principle of DRY (don’t repeat yourself) and a model-view-template architectural pattern.

It is widely popular among developers as it has a vast collection of libraries written in the Python language. It emphasizes efficiency, the reusability of components, and less code. Some of the main features of Django are URL routing, object-relational mapper (ORM), authentication mechanism, template engine, and database schema migrations.

Django implements ORM to map its instances to database tables. It provides support for multiple databases such as PostgreSQL, MySQL, SQLite, and Oracle. Hence, it becomes easier for developers to transfer the code from one database to another. In addition, it also provides support for web servers. Because of its amazing features, Django is widely used by most of the renowned companies such as Instagram, Pinterest, Disqus, Mozilla, The Washington Times, and Bitbucket.

2. Web2py

由 Massimo De Pierro 开发的 Web2py 是一个用 Python 编程语言编写的跨平台 Web 应用程序框架。 它是一个开源且免费使用的 Python Web 框架,于 2007 年 9 月发布。 它使用户能够在 Python 中创建动态 Web 内容。 Web2py 框架附带了代码编辑器,调试器和部署工具,您可以使用它来开发和调试代码,以及测试和维护应用程序。 它包含一个票务系统,可在发生错误时向用户发出票证。 此票证可帮助用户跟踪错误的状态。

Some of the main features of the Web2py Python framework are:

Cross-platform framework that provides support for Windows, Unix/Linux, Mac, Google App Engine, and many other platforms. No additional installation and configuration. Built-in components to handle HTTP requests, HTTP responses, cookies, and sessions as well. Ability to read multiple protocols. Security to data against all possible threats such as cross-site scripting, injection flaws, and execution of infected files. Follows model-view-controller (MVC) pattern. Support for role-based access control and internationalization. Allows users to embed jQuery for Ajax and UI effects.

3. 涡轮增压器 TurboGears

由 KevinDangoor 和 Mark Ramm 开发的 TurboGears 是一个全栈 Web 应用程序框架。 它是一个数据驱动,开源和免费使用的 Python Web 框架。 借助 WebOb,SQLAlchemy,Genshi 和 Repoze 等组件,与其他现有框架相比,您可以更轻松地开发需要数据库连接的应用程序。

Some of the main features of TurboGears are:

Support for multiple databases. Follows an MVC pattern. Support for web servers such as Pylons. Numerous libraries. WSGI (Web Server Gateway Interface) components. For example, it uses ToscaWidgets, which enable developers to embed any complex widget in their application. New call-to-action

4. 立方网 CubicWeb

由 Logilab 开发的 CubicWeb 是一个开源,语义和免费使用的 Python Web 框架。 该框架基于数据模型。 您需要定义数据模型才能获得功能性应用程序。 它使用多维数据集代替使用单独的视图和模型。 在一些配置文件,Web 服务器和数据库的帮助下,将多个多维数据集连接在一起以创建实例。

Some of the main features of CubicWeb are:

Multiple databases, security workflows, and reusable components. Support for Web Ontology Language (OWL) and Resource Description Framework (RDF). Embeds Relational Query Language (RQL) in order to simplify the queries related to data.

5. 乔托 Giotto

Giotto 是一个基于 MVC(模型视图控制器)模式的 Python 框架。 它将 Model,View 和 Controller 元素分开,以确保 Web 设计人员,Web 开发人员和系统管理员可以独立有效地执行其功能。

Apart from this, it also incorporates controller modules, which enables users to create applications on top of the web, irc, or command line.

6. 铁塔 Pylon

Pylon 于 2010 年 12 月开发,是一个轻量级的 Python Web 框架。 它强调应用程序的快速发展。 它是使用 Ruby,Python 和 Perl 等语言中的一些最佳创意开发的。 因此,它为 Web 开发提供了高度灵活的结构。

Note: The Pylon framework is in maintenance mode, after being merged with Pyramid to make Pylons project in order to develop Python-based web technologies.

Non-full-stack Frameworks The non-full-stack frameworks do not provide additional functionalities and features to the users. Developers need to add a lot of code and other things manually. Some commonly used Python frameworks are:

7. 瓶子 Bottle

由 Marcel Hellkemp 开发的瓶子是一个微框架。 它是一个易于使用的轻量级框架,通常用于构建小型 Web 应用程序。 它为每个项目或应用程序创建单个源文件。 除了 Python 标准库之外,它没有其他依赖性。

Some of the basic features of the Bottle framework are:

Built-in HTTP server. Adapters for third-party template engines and WSGI/HTTP servers. Allows users to access form data, file uploads, cookies, and other HTTP-related metadata in a much simpler way. Provides request-dispatching routes having URL-parameter support. Support for plugins of different databases.

8. 樱桃 CherryPy

CherryPy 是一个面向对象的开源 Python 框架。 Remi Delon is known as the founder of the CherryPy project. The CherryPy framework is widely implemented by developers to create Python web applications. It has its own multi-threaded web server.

You can create applications using CherryPy that will run on any Python-supporting operating systems such as Windows, Linux/Unix, and macOS.

Some of the common features of CherryPy are:

Contains an HTTP/1.1-compliant, WSGI threaded-pooled web server. It provides support for different web servers as well, for example, Apache and IIS. Allows you to run several HTTP servers simultaneously. Contains some tools for events such as caching, encoding, authorization, etc. by default. Support for profiling, testing, and coverage by default. Built-in plugin system.

9. 烧瓶 Flask

Flask 由 Armin Ronacher 开发,是一个功能强大的 Python Web 应用程序框架。 它通常被称为微框架,因为它没有以下元素:

  • 特定工具和库
  • 没有数据库抽象层
  • 没有表单验证

The functionalities provided by the above-mentioned elements are now provided by third-party libraries. It depends on the Werkzeug WSGI toolkit and Jinja2template. Some of the common features of the Flask framework are:

  • 内置开发服务器和调试器也。
  • 支持单元测试。
  • 包含 RESTful 请求调度。
  • 建立安全的客户端会话。
  • 与 Google App Engine 兼容。

10. Sanic

Sanic 是一个简单,开源,简单的 Python 框架。 这个框架在功能上类似于 Flask,但相对来说速度要快得多。 它是专门为异步请求处理程序的快速 HTTP 响应而设计的。

在使用 Sanic 框架进行基准测试期间取得了显着的成绩。 据记录,Sanic 框架有可能在一秒钟内处理 33,342 个请求。 这个统计数据足以显示 Sanic 的速度。

新的号召性用语

11. 龙卷风 Tornado

由 Ben Darnell 和 Bret Taylor 开发的 Tornado 是一个 Python Web 应用程序框架。 最初,它是为一家名为 FriendFeed 的公司开发的,该公司后来于 2009 年被 Facebook 接管。 Tornado 是一个开源框架,通常以其高性能而闻名。 它使用非阻塞网络 I / O,能够一次处理 10,000 多个连接。

Tornado 框架的一些主要功能是:

默认支持用户身份验证。 提供高质量的输出。 非阻塞 HTTP 客户端。 允许您实施第三方身份验证和授权方案,例如 Google OpenID / OAuth,Facebook 登录,Yahoo BBAuth 和 Twitter OAuth。

哪个 Python 框架最好?

每个框架都有优点和缺点,每个开发人员都有不同的编码风格和偏好。 我们希望您在我们的列表中找到对您和您的团队有价值的框架。

在我们的博客上获取有关软件开发的最新新闻,提示和指南。 立即注册我们的双周通讯!