### 导航
- [索引](../genindex.xhtml "总目录")
- [模块](../py-modindex.xhtml "Python 模块索引") |
- [下一页](intro.xhtml "概述") |
- [上一页](../reference/grammar.xhtml "10. 完整的语法规范") |
- ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png)
- [Python](https://www.python.org/) »
- zh\_CN 3.7.3 [文档](../index.xhtml) »
- $('.inline-search').show(0); |
# Python 标准库
[Python 语言参考](../reference/index.xhtml#reference-index) 描述了 Python 语言的具体语法和语义,这份库参考则介绍了与 Python 一同发行的标准库。它还描述了通常包含在 Python 发行版中的一些可选组件。
Python 标准库非常庞大,所提供的组件涉及范围十分广泛,正如以下内容目录所显示的。这个库包含了多个内置模块 (以 C 编写),Python 程序员必须依靠它们来实现系统级功能,例如文件 I/O,此外还有大量以 Python 编写的模块,提供了日常编程中许多问题的标准解决方案。其中有些模块经过专门设计,通过将特定平台功能抽象化为平台中立的 API 来鼓励和加强 Python 程序的可移植性。
Windows 版本的 Python 安装程序通常包含整个标准库,往往还包含许多额外组件。对于类 Unix 操作系统,Python 通常会分成一系列的软件包,因此可能需要使用操作系统所提供的包管理工具来获取部分或全部可选组件。
在这个标准库以外还存在成千上万并且不断增加的其他组件 (从单独的程序、模块、软件包直到完整的应用开发框架),访问 [Python 包索引](https://pypi.org) \[https://pypi.org\] 即可获取这些第三方包。
- [概述](intro.xhtml)
- [可用性注释](intro.xhtml#notes-on-availability)
- [内置函数](functions.xhtml)
- [内置常量](constants.xhtml)
- [由 `site` 模块添加的常量](constants.xhtml#constants-added-by-the-site-module)
- [内置类型](stdtypes.xhtml)
- [逻辑值检测](stdtypes.xhtml#truth-value-testing)
- [布尔运算 --- `and`, `or`, `not`](stdtypes.xhtml#boolean-operations-and-or-not)
- [比较](stdtypes.xhtml#comparisons)
- [数字类型 --- `int`, `float`, `complex`](stdtypes.xhtml#numeric-types-int-float-complex)
- [迭代器类型](stdtypes.xhtml#iterator-types)
- [序列类型 --- `list`, `tuple`, `range`](stdtypes.xhtml#sequence-types-list-tuple-range)
- [文本序列类型 --- `str`](stdtypes.xhtml#text-sequence-type-str)
- [二进制序列类型 --- `bytes`, `bytearray`, `memoryview`](stdtypes.xhtml#binary-sequence-types-bytes-bytearray-memoryview)
- [集合类型 --- `set`, `frozenset`](stdtypes.xhtml#set-types-set-frozenset)
- [映射类型 --- `dict`](stdtypes.xhtml#mapping-types-dict)
- [上下文管理器类型](stdtypes.xhtml#context-manager-types)
- [其他内置类型](stdtypes.xhtml#other-built-in-types)
- [特殊属性](stdtypes.xhtml#special-attributes)
- [内置异常](exceptions.xhtml)
- [基类](exceptions.xhtml#base-classes)
- [具体异常](exceptions.xhtml#concrete-exceptions)
- [警告](exceptions.xhtml#warnings)
- [异常层次结构](exceptions.xhtml#exception-hierarchy)
- [文本处理服务](text.xhtml)
- [`string` --- 常见的字符串操作](string.xhtml)
- [`re` --- 正则表达式操作](re.xhtml)
- [模块 difflib 是一个计算差异的助手](difflib.xhtml)
- [`textwrap` --- Text wrapping and filling](textwrap.xhtml)
- [`unicodedata` --- Unicode 数据库](unicodedata.xhtml)
- [`stringprep` --- Internet String Preparation](stringprep.xhtml)
- [`readline` --- GNU readline interface](readline.xhtml)
- [`rlcompleter` --- GNU readline的完成函数](rlcompleter.xhtml)
- [二进制数据服务](binary.xhtml)
- [`struct` --- Interpret bytes as packed binary data](struct.xhtml)
- [`codecs` --- Codec registry and base classes](codecs.xhtml)
- [数据类型](datatypes.xhtml)
- [`datetime` --- 基础日期/时间数据类型](datetime.xhtml)
- [`calendar` --- General calendar-related functions](calendar.xhtml)
- [`collections` --- 容器数据类型](collections.xhtml)
- [`collections.abc` --- 容器的抽象基类](collections.abc.xhtml)
- [`heapq` --- 堆队列算法](heapq.xhtml)
- [`bisect` --- Array bisection algorithm](bisect.xhtml)
- [`array` --- Efficient arrays of numeric values](array.xhtml)
- [`weakref` --- 弱引用](weakref.xhtml)
- [`types` --- Dynamic type creation and names for built-in types](types.xhtml)
- [`copy` --- 浅层 (shallow) 和深层 (deep) 复制操作](copy.xhtml)
- [`pprint` --- 数据美化输出](pprint.xhtml)
- [`reprlib` --- Alternate `repr()` implementation](reprlib.xhtml)
- [`enum` --- Support for enumerations](enum.xhtml)
- [数字和数学模块](numeric.xhtml)
- [`numbers` --- 数字的抽象基类](numbers.xhtml)
- [`math` --- 数学函数](math.xhtml)
- [`cmath` --- Mathematical functions for complex numbers](cmath.xhtml)
- [`decimal` --- 十进制定点和浮点运算](decimal.xhtml)
- [`fractions` --- 分数](fractions.xhtml)
- [`random` --- 生成伪随机数](random.xhtml)
- [`statistics` --- Mathematical statistics functions](statistics.xhtml)
- [函数式编程模块](functional.xhtml)
- [`itertools` --- 为高效循环而创建迭代器的函数](itertools.xhtml)
- [`functools` --- 高阶函数和可调用对象上的操作](functools.xhtml)
- [`operator` --- 标准运算符替代函数](operator.xhtml)
- [文件和目录访问](filesys.xhtml)
- [`pathlib` --- 面向对象的文件系统路径](pathlib.xhtml)
- [`os.path` --- 常见路径操作](os.path.xhtml)
- [`fileinput` --- Iterate over lines from multiple input streams](fileinput.xhtml)
- [`stat` --- Interpreting `stat()` results](stat.xhtml)
- [`filecmp` --- File and Directory Comparisons](filecmp.xhtml)
- [`tempfile` --- Generate temporary files and directories](tempfile.xhtml)
- [`glob` --- Unix style pathname pattern expansion](glob.xhtml)
- [`fnmatch` --- Unix filename pattern matching](fnmatch.xhtml)
- [`linecache` --- Random access to text lines](linecache.xhtml)
- [`shutil` --- High-level file operations](shutil.xhtml)
- [`macpath` --- Mac OS 9 路径操作函数](macpath.xhtml)
- [数据持久化](persistence.xhtml)
- [`pickle` —— Python 对象序列化](pickle.xhtml)
- [`copyreg` --- Register `pickle` support functions](copyreg.xhtml)
- [`shelve` --- Python object persistence](shelve.xhtml)
- [`marshal` --- Internal Python object serialization](marshal.xhtml)
- [`dbm` --- Interfaces to Unix "databases"](dbm.xhtml)
- [`sqlite3` --- SQLite 数据库 DB-API 2.0 接口模块](sqlite3.xhtml)
- [数据压缩和存档](archiving.xhtml)
- [`zlib` --- 与 **gzip** 兼容的压缩](zlib.xhtml)
- [`gzip` --- 对 **gzip** 格式的支持](gzip.xhtml)
- [`bz2` --- 对 **bzip2** 压缩算法的支持](bz2.xhtml)
- [`lzma` --- 用 LZMA 算法压缩](lzma.xhtml)
- [`zipfile` --- 在 ZIP 归档中工作](zipfile.xhtml)
- [`tarfile` --- Read and write tar archive files](tarfile.xhtml)
- [文件格式](fileformats.xhtml)
- [`csv` --- CSV 文件读写](csv.xhtml)
- [`configparser` --- Configuration file parser](configparser.xhtml)
- [`netrc` --- netrc file processing](netrc.xhtml)
- [`xdrlib` --- Encode and decode XDR data](xdrlib.xhtml)
- [`plistlib` --- Generate and parse Mac OS X `.plist` files](plistlib.xhtml)
- [加密服务](crypto.xhtml)
- [`hashlib` --- 安全哈希与消息摘要](hashlib.xhtml)
- [`hmac` --- 基于密钥的消息验证](hmac.xhtml)
- [`secrets` --- Generate secure random numbers for managing secrets](secrets.xhtml)
- [通用操作系统服务](allos.xhtml)
- [`os` --- 操作系统接口模块](os.xhtml)
- [`io` --- 处理流的核心工具](io.xhtml)
- [`time` --- 时间的访问和转换](time.xhtml)
- [`argparse` --- 命令行选项、参数和子命令解析器](argparse.xhtml)
- [`getopt` --- C-style parser for command line options](getopt.xhtml)
- [模块 `logging` --- Python 的日志记录工具](logging.xhtml)
- [`logging.config` --- 日志记录配置](logging.config.xhtml)
- [`logging.handlers` --- Logging handlers](logging.handlers.xhtml)
- [`getpass` --- 便携式密码输入工具](getpass.xhtml)
- [`curses` --- 终端字符单元显示的处理](curses.xhtml)
- [`curses.textpad` --- Text input widget for curses programs](curses.xhtml#module-curses.textpad)
- [`curses.ascii` --- Utilities for ASCII characters](curses.ascii.xhtml)
- [`curses.panel` --- A panel stack extension for curses](curses.panel.xhtml)
- [`platform` --- Access to underlying platform's identifying data](platform.xhtml)
- [`errno` --- Standard errno system symbols](errno.xhtml)
- [`ctypes` --- Python 的外部函数库](ctypes.xhtml)
- [并发执行](concurrency.xhtml)
- [`threading` --- 基于线程的并行](threading.xhtml)
- [`multiprocessing` --- 基于进程的并行](multiprocessing.xhtml)
- [`concurrent` 包](concurrent.xhtml)
- [`concurrent.futures` --- 启动并行任务](concurrent.futures.xhtml)
- [`subprocess` --- 子进程管理](subprocess.xhtml)
- [`sched` --- 事件调度器](sched.xhtml)
- [`queue` --- 一个同步的队列类](queue.xhtml)
- [`_thread` --- 底层多线程 API](_thread.xhtml)
- [`_dummy_thread` --- `_thread` 的替代模块](_dummy_thread.xhtml)
- [`dummy_threading` --- 可直接替代 `threading` 模块。](dummy_threading.xhtml)
- [`contextvars` --- Context Variables](contextvars.xhtml)
- [Context Variables](contextvars.xhtml#context-variables)
- [Manual Context Management](contextvars.xhtml#manual-context-management)
- [asyncio support](contextvars.xhtml#asyncio-support)
- [网络和进程间通信](ipc.xhtml)
- [`asyncio` --- 异步 I/O](asyncio.xhtml)
- [`socket` --- 底层网络接口](socket.xhtml)
- [`ssl` --- TLS/SSL wrapper for socket objects](ssl.xhtml)
- [`select` --- Waiting for I/O completion](select.xhtml)
- [`selectors` --- 高级 I/O 复用库](selectors.xhtml)
- [`asyncore` --- 异步socket处理器](asyncore.xhtml)
- [`asynchat` --- 异步 socket 指令/响应 处理器](asynchat.xhtml)
- [`signal` --- Set handlers for asynchronous events](signal.xhtml)
- [`mmap` --- Memory-mapped file support](mmap.xhtml)
- [互联网数据处理](netdata.xhtml)
- [`email` --- 电子邮件与 MIME 处理包](email.xhtml)
- [`json` --- JSON 编码和解码器](json.xhtml)
- [`mailcap` --- Mailcap file handling](mailcap.xhtml)
- [`mailbox` --- Manipulate mailboxes in various formats](mailbox.xhtml)
- [`mimetypes` --- Map filenames to MIME types](mimetypes.xhtml)
- [`base64` --- Base16, Base32, Base64, Base85 数据编码](base64.xhtml)
- [`binhex` --- 对binhex4文件进行编码和解码](binhex.xhtml)
- [`binascii` --- 二进制和 ASCII 码互转](binascii.xhtml)
- [`quopri` --- Encode and decode MIME quoted-printable data](quopri.xhtml)
- [`uu` --- Encode and decode uuencode files](uu.xhtml)
- [结构化标记处理工具](markup.xhtml)
- [`html` --- 超文本标记语言支持](html.xhtml)
- [`html.parser` --- 简单的 HTML 和 XHTML 解析器](html.parser.xhtml)
- [`html.entities` --- HTML 一般实体的定义](html.entities.xhtml)
- [XML处理模块](xml.xhtml)
- [`xml.etree.ElementTree` --- The ElementTree XML API](xml.etree.elementtree.xhtml)
- [`xml.dom` --- The Document Object Model API](xml.dom.xhtml)
- [`xml.dom.minidom` --- Minimal DOM implementation](xml.dom.minidom.xhtml)
- [`xml.dom.pulldom` --- Support for building partial DOM trees](xml.dom.pulldom.xhtml)
- [`xml.sax` --- Support for SAX2 parsers](xml.sax.xhtml)
- [`xml.sax.handler` --- Base classes for SAX handlers](xml.sax.handler.xhtml)
- [`xml.sax.saxutils` --- SAX Utilities](xml.sax.utils.xhtml)
- [`xml.sax.xmlreader` --- Interface for XML parsers](xml.sax.reader.xhtml)
- [`xml.parsers.expat` --- Fast XML parsing using Expat](pyexpat.xhtml)
- [互联网协议和支持](internet.xhtml)
- [`webbrowser` --- 方便的Web浏览器控制器](webbrowser.xhtml)
- [`cgi` --- Common Gateway Interface support](cgi.xhtml)
- [`cgitb` --- Traceback manager for CGI scripts](cgitb.xhtml)
- [`wsgiref` --- WSGI Utilities and Reference Implementation](wsgiref.xhtml)
- [`urllib` --- URL 处理模块](urllib.xhtml)
- [`urllib.request` --- 用于打开 URL 的可扩展库](urllib.request.xhtml)
- [`urllib.response` --- Response classes used by urllib](urllib.request.xhtml#module-urllib.response)
- [`urllib.parse` --- Parse URLs into components](urllib.parse.xhtml)
- [`urllib.error` --- Exception classes raised by urllib.request](urllib.error.xhtml)
- [`urllib.robotparser` --- Parser for robots.txt](urllib.robotparser.xhtml)
- [`http` --- HTTP 模块](http.xhtml)
- [http.client --- HTTP协议客户端](http.client.xhtml)
- [`ftplib` --- FTP protocol client](ftplib.xhtml)
- [`poplib` --- POP3 protocol client](poplib.xhtml)
- [`imaplib` --- IMAP4 protocol client](imaplib.xhtml)
- [`nntplib` --- NNTP protocol client](nntplib.xhtml)
- [`smtplib` ---SMTP协议客户端](smtplib.xhtml)
- [`smtpd` --- SMTP Server](smtpd.xhtml)
- [`telnetlib` --- Telnet client](telnetlib.xhtml)
- [`uuid` --- UUID objects according to **RFC 4122**](uuid.xhtml)
- [`socketserver` --- A framework for network servers](socketserver.xhtml)
- [`http.server` --- HTTP 服务器](http.server.xhtml)
- [`http.cookies` --- HTTP state management](http.cookies.xhtml)
- [`http.cookiejar` --- Cookie handling for HTTP clients](http.cookiejar.xhtml)
- [`xmlrpc` --- XMLRPC 服务端与客户端模块](xmlrpc.xhtml)
- [`xmlrpc.client` --- XML-RPC client access](xmlrpc.client.xhtml)
- [`xmlrpc.server` --- Basic XML-RPC servers](xmlrpc.server.xhtml)
- [`ipaddress` --- IPv4/IPv6 manipulation library](ipaddress.xhtml)
- [多媒体服务](mm.xhtml)
- [`audioop` --- Manipulate raw audio data](audioop.xhtml)
- [`aifc` --- Read and write AIFF and AIFC files](aifc.xhtml)
- [`sunau` --- 读写 Sun AU 文件](sunau.xhtml)
- [`wave` --- 读写WAV格式文件](wave.xhtml)
- [`chunk` --- Read IFF chunked data](chunk.xhtml)
- [`colorsys` --- Conversions between color systems](colorsys.xhtml)
- [`imghdr` --- 推测图像类型](imghdr.xhtml)
- [`sndhdr` --- 推测声音文件的类型](sndhdr.xhtml)
- [`ossaudiodev` --- Access to OSS-compatible audio devices](ossaudiodev.xhtml)
- [国际化](i18n.xhtml)
- [`gettext` --- 多语种国际化服务](gettext.xhtml)
- [`locale` --- 国际化服务](locale.xhtml)
- [程序框架](frameworks.xhtml)
- [`turtle` --- 海龟绘图](turtle.xhtml)
- [`cmd` --- 支持面向行的命令解释器](cmd.xhtml)
- [`shlex` --- Simple lexical analysis](shlex.xhtml)
- [Tk图形用户界面(GUI)](tk.xhtml)
- [`tkinter` --- Tcl/Tk的Python接口](tkinter.xhtml)
- [`tkinter.ttk` --- Tk themed widgets](tkinter.ttk.xhtml)
- [`tkinter.tix` --- Extension widgets for Tk](tkinter.tix.xhtml)
- [`tkinter.scrolledtext` --- 滚动文字控件](tkinter.scrolledtext.xhtml)
- [IDLE](idle.xhtml)
- [其他图形用户界面(GUI)包](othergui.xhtml)
- [开发工具](development.xhtml)
- [`typing` --- 类型标注支持](typing.xhtml)
- [`pydoc` --- Documentation generator and online help system](pydoc.xhtml)
- [`doctest` --- Test interactive Python examples](doctest.xhtml)
- [`unittest` --- 单元测试框架](unittest.xhtml)
- [`unittest.mock` --- mock object library](unittest.mock.xhtml)
- [`unittest.mock` 上手指南](unittest.mock-examples.xhtml)
- [2to3 - 自动将 Python 2 代码转为 Python 3 代码](2to3.xhtml)
- [`test` --- Regression tests package for Python](test.xhtml)
- [`test.support` --- Utilities for the Python test suite](test.xhtml#module-test.support)
- [`test.support.script_helper` --- Utilities for the Python execution tests](test.xhtml#module-test.support.script_helper)
- [调试和分析](debug.xhtml)
- [`bdb` --- Debugger framework](bdb.xhtml)
- [`faulthandler` --- Dump the Python traceback](faulthandler.xhtml)
- [`pdb` --- The Python Debugger](pdb.xhtml)
- [The Python Profilers](profile.xhtml)
- [`timeit` --- 测量小代码片段的执行时间](timeit.xhtml)
- [`trace` --- Trace or track Python statement execution](trace.xhtml)
- [`tracemalloc` --- Trace memory allocations](tracemalloc.xhtml)
- [软件打包和分发](distribution.xhtml)
- [`distutils` --- 构建和安装 Python 模块](distutils.xhtml)
- [`ensurepip` --- Bootstrapping the `pip` installer](ensurepip.xhtml)
- [`venv` --- 创建虚拟环境](venv.xhtml)
- [`zipapp` --- Manage executable Python zip archives](zipapp.xhtml)
- [Python运行时服务](python.xhtml)
- [`sys` --- 系统相关的参数和函数](sys.xhtml)
- [`sysconfig` --- Provide access to Python's configuration information](sysconfig.xhtml)
- [`builtins` --- 内建对象](builtins.xhtml)
- [`__main__` --- 顶层脚本环境](__main__.xhtml)
- [`warnings` --- Warning control](warnings.xhtml)
- [`dataclasses` --- 数据类](dataclasses.xhtml)
- [`contextlib` --- Utilities for `with`-statement contexts](contextlib.xhtml)
- [`abc` --- 抽象基类](abc.xhtml)
- [`atexit` --- 退出处理器](atexit.xhtml)
- [`traceback` --- Print or retrieve a stack traceback](traceback.xhtml)
- [`__future__` --- Future 语句定义](__future__.xhtml)
- [`gc` --- 垃圾回收器接口](gc.xhtml)
- [`inspect` --- 检查对象](inspect.xhtml)
- [`site` --- Site-specific configuration hook](site.xhtml)
- [自定义 Python 解释器](custominterp.xhtml)
- [`code` --- Interpreter base classes](code.xhtml)
- [`codeop` --- Compile Python code](codeop.xhtml)
- [导入模块](modules.xhtml)
- [`zipimport` --- Import modules from Zip archives](zipimport.xhtml)
- [`pkgutil` --- Package extension utility](pkgutil.xhtml)
- [`modulefinder` --- 查找脚本使用的模块](modulefinder.xhtml)
- [`runpy` --- Locating and executing Python modules](runpy.xhtml)
- [`importlib` --- The implementation of `import`](importlib.xhtml)
- [Python 语言服务](language.xhtml)
- [`parser` --- Access Python parse trees](parser.xhtml)
- [`ast` --- 抽象语法树](ast.xhtml)
- [`symtable` --- Access to the compiler's symbol tables](symtable.xhtml)
- [`symbol` --- 与 Python 解析树一起使用的常量](symbol.xhtml)
- [`token` --- 与Python解析树一起使用的常量](token.xhtml)
- [`keyword` --- 检验Python关键字](keyword.xhtml)
- [`tokenize` --- Tokenizer for Python source](tokenize.xhtml)
- [`tabnanny` --- 模糊缩进检测](tabnanny.xhtml)
- [`pyclbr` --- Python class browser support](pyclbr.xhtml)
- [`py_compile` --- Compile Python source files](py_compile.xhtml)
- [`compileall` --- Byte-compile Python libraries](compileall.xhtml)
- [`dis` --- Python 字节码反汇编器](dis.xhtml)
- [`pickletools` --- Tools for pickle developers](pickletools.xhtml)
- [杂项服务](misc.xhtml)
- [`formatter` --- Generic output formatting](formatter.xhtml)
- [Windows系统相关模块](windows.xhtml)
- [`msilib` --- Read and write Microsoft Installer files](msilib.xhtml)
- [`msvcrt` --- Useful routines from the MS VC++ runtime](msvcrt.xhtml)
- [`winreg` --- Windows 注册表访问](winreg.xhtml)
- [`winsound` --- Sound-playing interface for Windows](winsound.xhtml)
- [Unix 专有服务](unix.xhtml)
- [`posix` --- The most common POSIX system calls](posix.xhtml)
- [`pwd` --- 用户密码数据库](pwd.xhtml)
- [`spwd` --- The shadow password database](spwd.xhtml)
- [`grp` --- The group database](grp.xhtml)
- [`crypt` --- Function to check Unix passwords](crypt.xhtml)
- [`termios` --- POSIX style tty control](termios.xhtml)
- [`tty` --- 终端控制功能](tty.xhtml)
- [`pty` --- Pseudo-terminal utilities](pty.xhtml)
- [`fcntl` --- The `fcntl` and `ioctl` system calls](fcntl.xhtml)
- [`pipes` --- Interface to shell pipelines](pipes.xhtml)
- [`resource` --- Resource usage information](resource.xhtml)
- [`nis` --- Interface to Sun's NIS (Yellow Pages)](nis.xhtml)
- [Unix syslog 库例程](syslog.xhtml)
- [被取代的模块](superseded.xhtml)
- [`optparse` --- Parser for command line options](optparse.xhtml)
- [`imp` --- Access the `import` internals](imp.xhtml)
- [未创建文档的模块](undoc.xhtml)
- [平台特定模块](undoc.xhtml#platform-specific-modules)
### 导航
- [索引](../genindex.xhtml "总目录")
- [模块](../py-modindex.xhtml "Python 模块索引") |
- [下一页](intro.xhtml "概述") |
- [上一页](../reference/grammar.xhtml "10. 完整的语法规范") |
- ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png)
- [Python](https://www.python.org/) »
- zh\_CN 3.7.3 [文档](../index.xhtml) »
- $('.inline-search').show(0); |
© [版权所有](../copyright.xhtml) 2001-2019, Python Software Foundation.
Python 软件基金会是一个非盈利组织。 [请捐助。](https://www.python.org/psf/donations/)
最后更新于 5月 21, 2019. [发现了问题](../bugs.xhtml)?
使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 创建。