Python 标准库
Python 语言参考 描述了 Python 语言的具体语法和语义,这份库参考则介绍了与 Python 一同发行的标准库。它还描述了通常包含在 Python 发行版中的一些可选组件。
Python 标准库非常庞大,所提供的组件涉及范围十分广泛,正如以下内容目录所显示的。这个库包含了多个内置模块 (以 C 编写),Python 程序员必须依靠它们来实现系统级功能,例如文件 I/O,此外还有大量以 Python 编写的模块,提供了日常编程中许多问题的标准解决方案。其中有些模块经过专门设计,通过将特定平台功能抽象化为平台中立的 API 来鼓励和加强 Python 程序的可移植性。
Windows 版本的 Python 安装程序通常包含整个标准库,往往还包含许多额外组件。对于类 Unix 操作系统,Python 通常会分成一系列的软件包,因此可能需要使用操作系统所提供的包管理工具来获取部分或全部可选组件。
在这个标准库以外还存在成千上万并且不断增加的其他组件 (从单独的程序、模块、软件包直到完整的应用开发框架),访问 Python 包索引 即可获取这些第三方包。
- 概述
- 内置函数
- 内置常量
- 内置类型
- 内置异常
- 文本处理服务
- 二进制数据服务
- 数据类型
- 数字和数学模块
- 函数式编程模块
- 文件和目录访问
- 数据持久化
- 数据压缩和存档
- 文件格式
- 加密服务
- 通用操作系统服务
os— 各种各样的操作系统接口io— 处理流的核心工具time— 时间的访问和转换argparse— 命令行选项、参数和子命令解析器getopt— C-style parser for command line optionslogging— Python 的日志记录工具logging.config— 日志记录配置logging.handlers— 日志处理getpass— 便携式密码输入工具curses— 终端字符单元显示的处理curses.textpad— Text input widget for curses programscurses.ascii— Utilities for ASCII characterscurses.panel— A panel stack extension for cursesplatform— 获取底层平台的标识数据errno— Standard errno system symbolsctypes— Python 的外部函数库
- 并发执行
contextvars— Context Variables- 网络和进程间通信
- 互联网数据处理
email— 电子邮件与 MIME 处理包json— JSON 编码和解码器mailcap— Mailcap file handlingmailbox— Manipulate mailboxes in various formatsmimetypes— Map filenames to MIME typesbase64— Base16, Base32, Base64, Base85 数据编码binhex— 对binhex4文件进行编码和解码binascii— 二进制和 ASCII 码互转quopri— 编码与解码经过 MIME 转码的可打印数据uu— 对 uuencode 文件进行编码与解码
- 结构化标记处理工具
html— 超文本标记语言支持html.parser— 简单的 HTML 和 XHTML 解析器html.entities— HTML 一般实体的定义- XML处理模块
xml.etree.ElementTree— ElementTree XML APIxml.dom— The Document Object Model APIxml.dom.minidom— Minimal DOM implementationxml.dom.pulldom— Support for building partial DOM treesxml.sax— Support for SAX2 parsersxml.sax.handler— Base classes for SAX handlersxml.sax.saxutils— SAX Utilitiesxml.sax.xmlreader— Interface for XML parsersxml.parsers.expat— Fast XML parsing using Expat
- 互联网协议和支持
webbrowser— 方便的Web浏览器控制器cgi— Common Gateway Interface supportcgitb— 用于 CGI 脚本的回溯管理器wsgiref— WSGI Utilities and Reference Implementationurllib— URL 处理模块urllib.request— 用于打开 URL 的可扩展库urllib.response— urllib 使用的 Response 类urllib.parse— Parse URLs into componentsurllib.error— urllib.request 引发的异常类urllib.robotparser— robots.txt 语法分析程序http— HTTP 模块http.client— HTTP 协议客户端ftplib— FTP 协议客户端poplib— POP3 protocol clientimaplib— IMAP4 protocol clientnntplib— NNTP protocol clientsmtplib—SMTP协议客户端smtpd— SMTP 服务器telnetlib— Telnet clientuuid— UUID objects according to RFC 4122socketserver— A framework for network servershttp.server— HTTP 服务器http.cookies— HTTP状态管理http.cookiejar—— HTTP 客户端的 Cookie 处理xmlrpc— XMLRPC 服务端与客户端模块xmlrpc.client— XML-RPC client accessxmlrpc.server— Basic XML-RPC serversipaddress— IPv4/IPv6 manipulation library
- 多媒体服务
- 国际化
- 程序框架
- Tk图形用户界面(GUI)
- 开发工具
typing— 类型标注支持pydoc— Documentation generator and online help systemdoctest— 测试交互性的Python示例unittest— 单元测试框架unittest.mock— mock对象库unittest.mock上手指南- 2to3 – 自动将 Python 2 代码转为 Python 3 代码
test— Regression tests package for Pythontest.support— Utilities for the Python test suitetest.support.script_helper— Utilities for the Python execution tests
- 调试和分析
- 软件打包和分发
- Python运行时服务
sys— 系统相关的参数和函数sysconfig— Provide access to Python’s configuration informationbuiltins— 内建对象__main__— 顶层脚本环境warnings— Warning controldataclasses— 数据类contextlib— Utilities forwith-statement contextsabc— 抽象基类atexit— 退出处理器traceback— 打印或检索堆栈回溯__future__— Future 语句定义gc— 垃圾回收器接口inspect— 检查对象site— Site-specific configuration hook
- 自定义 Python 解释器
- 导入模块
- Python 语言服务
parser— Access Python parse treesast— 抽象语法树symtable— Access to the compiler’s symbol tablessymbol— 与 Python 解析树一起使用的常量token— 与Python解析树一起使用的常量keyword— 检验Python关键字tokenize— Tokenizer for Python sourcetabnanny— 模糊缩进检测pyclbr— Python class browser supportpy_compile— Compile Python source filescompileall— Byte-compile Python librariesdis— Python 字节码反汇编器pickletools— Tools for pickle developers
- 杂项服务
- Windows系统相关模块
- Unix 专有服务
posix— The most common POSIX system callspwd— 用户密码数据库spwd— The shadow password databasegrp— The group databasecrypt— Function to check Unix passwordstermios— POSIX style tty controltty— 终端控制功能pty— Pseudo-terminal utilitiesfcntl— Thefcntlandioctlsystem callspipes— Interface to shell pipelinesresource— Resource usage informationnis— Interface to Sun’s NIS (Yellow Pages)- Unix syslog 库例程
- 被取代的模块
- 未创建文档的模块
