The Python standard library¶
This library reference manual describes the standard library distributed with Python. It also describes some of the optional components that are commonly included in Python distributions.
Elsewhere, Python 语言参考手册 describes the exact syntax and semantics of the Python language, and Python built-ins reference describes the built-in functions.
Python's standard library is extensive, offering a wide range of facilities as indicated by the long table of contents listed below. The library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers, as well as modules written in Python that provide standardized solutions for many problems that occur in everyday programming. Some of these modules are explicitly designed to encourage and enhance the portability of Python programs by abstracting away platform-specifics into platform-neutral APIs.
Windows 版本的 Python 安装程序通常包含整个标准库,往往还包含许多额外组件。对于类 Unix 操作系统,Python 通常会分成一系列的软件包,因此可能需要使用操作系统所提供的包管理工具来获取部分或全部可选组件。
在标准库以外,还存在一个由数十万个组件(从单独的程序和模块到软件包以及完整的应用程序开发框架)组成的活跃合集,可以从 Python 包索引 获取。
- 概述
- 文本处理服务
- 二进制数据服务
- 数据类型
datetime--- 基本日期和时间类型zoneinfo--- IANA 时区支持calendar--- 通用日历相关函数collections--- 容器数据类型collections.abc--- 容器的抽象基类heapq--- 堆队列算法bisect--- 数组二分算法array--- 高效的数值数组weakref--- 弱引用types--- 动态类型创建和内置类型名称copy--- 浅层及深层拷贝操作pprint--- 数据美化输出reprlib--- 替代性repr()实现enum--- 对枚举的支持graphlib--- 操作类似图的结构的功能
- 数字和数学模块
- 函数式编程模块
- 文件和目录访问
- 数据持久化
- 数据压缩和存档
- 文件格式
- 加密服务
- 通用操作系统服务
- 命令行界面库
- 并发执行
- 网络和进程间通信
- 互联网数据处理
- 结构化标记处理工具
html--- 超文本标记语言支持html.parser--- 简单的 HTML 和 XHTML 解析器html.entities--- HTML 一般实体的定义- XML 处理模块
xml.etree.ElementTree--- ElementTree XML APIxml.dom--- 文档对象模型 APIxml.dom.minidom--- 最小化的 DOM 实现xml.dom.pulldom--- 对构建部分 DOM 树的支持xml.sax--- SAX2 解析器支持xml.sax.handler--- SAX 处理器的基类xml.sax.saxutils--- SAX 工具集xml.sax.xmlreader--- 用于 XML 解析器的接口xml.parsers.expat--- 使用 Expat 进行快速 XML 解析
- 互联网协议和支持
webbrowser--- 方便的 Web 浏览器控制工具wsgiref--- WSGI 工具和参考实现urllib--- URL 处理模块urllib.request--- 用于打开 URL 的可扩展库urllib.response--- urllib 使用的响应类urllib.parse--- 将 URL 解析为组件urllib.error--- 由 urllib.request 引发的异常类urllib.robotparser--- 用于 robots.txt 的解析器http--- HTTP 模块http.client--- HTTP 协议客户端ftplib--- FTP 协议客户端poplib--- POP3 协议客户端imaplib--- IMAP4 协议客户端smtplib--- SMTP 协议客户端uuid--- 根据 RFC 9562 定义的 UUID 对象socketserver--- 用于网络服务器的框架http.server--- HTTP 服务器http.cookies--- HTTP 状态管理http.cookiejar--- HTTP 客户端的 Cookie 处理xmlrpc--- XMLRPC 服务端与客户端模块xmlrpc.client--- XML-RPC 客户端访问xmlrpc.server--- 基本 XML-RPC 服务器ipaddress--- IPv4/IPv6 操作库
- 多媒体服务
- 国际化
- 使用 Tk 创建图形用户界面
- 开发工具
typing--- 对类型提示的支持pydoc--- 文档生成器和在线帮助系统- Python 开发模式
doctest--- 测试交互式的 Python 示例unittest--- 单元测试框架unittest.mock--- 模拟对象库unittest.mock--- 新手入门test--- Python 回归测试包test.support--- 针对 Python 测试套件的工具test.support.socket_helper--- 针对套接字测试的工具test.support.script_helper--- 用于 Python 执行测试的工具test.support.bytecode_helper--- 用于测试正确字节码生成的支持工具test.support.threading_helper--- 用于线程测试的工具test.support.os_helper--- 用于操作系统测试的工具test.support.import_helper--- 用于导入测试的工具Utilities for import teststest.support.warnings_helper--- 用于警告测试的工具Utilities for warnings tests
- Debugging and Profiling
- 软件打包和分发
- Python 运行时服务
sys--- 系统相关的形参和函数sys.monitoring--- 执行事件监测sysconfig--- 提供对 Python 配置信息的访问builtins--- 内置对象__main__--- 最高层级代码环境warnings--- 警告信息控制dataclasses--- 数据类contextlib--- 为with语句上下文提供的工具abc--- 抽象基类atexit--- 退出处理器traceback--- 打印或读取栈回溯信息__future__--- Future 语句定义gc--- 垃圾回收器接口inspect--- 检查活动对象annotationlib--- 用于内省注解的功能site--- 站点专属的配置钩子
- 自定义 Python 解释器
- 导入模块
- Python 语言服务
- Windows 系统相关模块
- Unix 专属服务
- 模块命令行界面(CLI)
- Superseded Modules
- 移除的模块
- 安全考量