尽管Python标准库已经非常丰富了，但也有一个由第三方开发人员提供的、可从 Python 包索引 获得模块的生态系统。本附录描述了其中的一些模块，包括您可能使用它们来补充或甚至替换标准库的情况。
PLY 包支持一 GNU 工具 LXX 合 YACC 的方式构建语法分析器，通常用于构建语言编译器。通过提供描述有效的指令输入、语法和每次遇到时采取的操作，可以构建完全功能的编译和解释器，以及更直接的数据解析器。
最后, NLTK 是处理自然语言文本的一个软件包——人类语言而不是计算机语言。它支持将句子解析为词类、查找词根形式和基本语义处理。
lxml 包封装了 libxml2 和 libxslt 库，为我们提供了除 [
xml.etree.ElementTree](https://pymotw.com/3/ xml.etree.ElementTree/index.html#module-xml.etree.ElementTree "xml.etree.ElementTree：XML Manipulation API") 中的 XML 解析器外的另一个选择。熟悉使用其他语言的开发人员可能会发现在 Python 中使用 lxml 会更容易一些。
The team building the cryptography package says "Our goal is for it to be your 'cryptographic standard library'." The cryptography package exposes high-level APIs to make it easy to add cryptographic features to applications and the package is actively maintained with frequent releases to address vulnerabilities in the underlying libraries such as OpenSSL.
Concurrency with Processes, Threads, and Coroutines
The event loop built into
asyncio is a reference implementation based on the abstract API defined by the module. It is possible to replace the event loop with a library such as uvloop, which gives better performance in exchange for adding extra application dependencies.
The curio package is another concurrency package similar to asyncio but with a smaller API that treats everything as a coroutine and does not support callbacks in the way asyncio does.
The Twisted library provides an extensible framework for Python programming, with special focus on event-based network programming and multiprotocol integration. It is mature, robust, and well-documented.
The requests package is a very popular replacement for
urllib.request. It provides a consistent API for working with remote resources addressable via HTTP, includes robust SSL support, and can use connection pooling for better performance in multi-threaded applications. It also provides features that make it well suited for accessing REST APIs, such as built-in JSON parsing.
html module includes a basic parser for well-formed HTML data. However, real world data is rarely well structured, making parsing it problematic. The BeautifulSoup and PyQuery libraries are alternatives to
html that are more robust in the face of messy data. Both define APIs for parsing, modifying, and constructing HTML.
http.server package includes base classes for creating simple HTTP servers from scratch. It does not offer much support beyond that for building web-based applications, though. The Django and Pyramid packages are two popular web application frameworks that provide more support for advanced features like request parsing, URL routing, and cookie handling.
Many existing libraries do not work with
asyncio because they do not integrate with the event loop. A new set of libraries such as aiohttp is being created to fill this gap as part of the aio-libs project.
The API for
imaplib is relatively low-level, requiring the caller to understand the IMAP protocol to build queries and parse results. The imapclientpackage provides a higher-level API that is easier to work with for building applications that need to manipulate IMAP mailboxes.
Application Building Blocks
The two standard library modules for building command line interfaces,
getopt, both separate the definition of command line arguments from their parsing and value processing. Alternatively, click (the "Command Line Interface Construction Kit"), works by defining command processing functions and then associating option and prompt definitions with those commands using decorators.
cliff ("Command Line Interface Formulation Framework") provides a set of base classes for defining commands and a plugin system for extending applications with multiple sub-commands that can be distributed in separate packages. It uses
argparse to build the help text and argument parser, so the command line processing is familiar.
The docopt package reverses the typical flow by asking the developer to write the help text for a program, which it then parses to understand the sub-commands, valid combinations of options, and sub-commands.
For interactive terminal-based programs, prompt_toolkit includes advanced features like color support, syntax highlighting, input editing, mouse support, and searchable history. It can be used to build command-oriented programs with a prompt loop like the
cmd module, or full-screen applications like text editors.
While INI files such as used by
configparser continue to be popular for application configuration, the YAML file format is also very popular. YAML provides many of the data structure features of JSON in a format that is easier for people to read. The PyYAML library provides access to a YAML parser and serializer.
The fixtures package provides several test resource management classes tailor made to work with the
addCleanup() method of test cases from the
unittest module. The provided fixture classes can manage loggers, environment variables, temporary files, and more in a consistent and safe way that ensures each test case is completely isolated from others in the suite.
distutils module in the standard library for packaging Python modules for distribution and reuse is deprecated. The replacement, setuptools, is packaged separately from the standard library to make it easier to deliver new versions frequently. The API for setuptools includes tools for building the list of files to include in a package. There are extensions to automatically build the list from the set of files managed by a version control system. For example, using setuptools-git with source in a git repository causes all of the tracked files to be included in the package by default. After a package is built, the twine application will upload it to the package index to be shared with other developers.
tabnanny are good at finding common formatting mistakes in Python code. The Python Code Quality Authority maintains an extensive range of more advanced static analysis tools, including tools that enforce style guidelines, find common programming errors, and even help avoid excessive complexity.
- Python Package Index or PyPI -- The site for finding and downloading extension modules distributed separately from the Python runtime.
我们的翻译工作遵照 CC 协议，如果我们的工作有侵犯到您的权益，请及时联系我们。