Python 標準函式庫 (Standard Library)¶
Python语言参考 說明 Python 這門語言確切的文法及語意,而這份函式庫參考手冊則是說明隨著 Python 一起發佈的標準函式庫,除此之外,其內容也包含一些時常出現在 Python 發佈版本中的非必要套件。
Python 的標準函式庫是非常龐大的,其提供了如下所述極多且涵蓋用途極廣的許多模組。包含一些用 C 語言撰寫,可以操作像是檔案讀寫等系統相關功能的內建模組,當然也有用 Python 撰寫,並使用標準解法解決許多常見問題的模組。其中有些模組則是特別針對 Python 的可攜性去設計的,為此特地將一些平台特殊相依性的功能抽象化成可跨平台的 API。
Python 的 Windows 安裝檔基本上包含整個標準函式庫,且通常也包含許多額外套件;而類 Unix 作業系統方面,Python 則提供一系列的套件,對於某些非必要性的套件,可能得使用該作業系統提供的套件管理工具來安裝。
在这个标准库以外还存在成千上万并且不断增加的其他组件 (从单独的程序、模块、软件包直到完整的应用开发框架),访问 Python 包索引 即可获取这些第三方包。
- 1. 簡介
- 2. 內建函式
- 3. 內建常數
- 4. 內建型態
- 5. 內建的例外
- 6. 文本处理服务
- 7. 二进制数据服务
- 8. 数据类型
- 8.1.
datetime
— 基本的日期和时间类型 - 8.2.
calendar
— 日历相关函数 - 8.3.
collections
— 容器資料型態 - 8.4.
collections.abc
— 容器的抽象基类 - 8.5.
heapq
— 堆積佇列 (heap queue) 演算法 - 8.6.
bisect
— 陣列二分演算法 (Array bisection algorithm) - 8.7.
array
— 高效率的數值型態陣列 - 8.8.
weakref
— 弱引用 - 8.9.
types
— 动态类型创建和内置类型名称 - 8.10.
copy
— 浅层 (shallow) 和深层 (deep) 复制操作 - 8.11.
pprint
— 数据美化输出 - 8.12.
reprlib
— 另一种repr()
实现 - 8.13.
enum
— 枚举类型支持
- 8.1.
- 9. 數值與數學模組
- 10. 函式編程模組
- 11. 檔案與目錄存取
- 11.1.
pathlib
— 面向对象的文件系统路径 - 11.2.
os.path
— 常见路径操作 - 11.3.
fileinput
— 迭代来自多个输入流的行 - 11.4.
stat
— 解析stat()
结果 - 11.5.
filecmp
— 文件及目录的比较 - 11.6.
tempfile
— 生成临时文件和目录 - 11.7.
glob
— Unix style pathname pattern expansion - 11.8.
fnmatch
— Unix 文件名模式匹配 - 11.9.
linecache
— 随机读写文本行 - 11.10.
shutil
— 高阶文件操作 - 11.11.
macpath
— Mac OS 9 路径操作函数
- 11.1.
- 12. 数据持久化
- 13. 資料壓縮與保存
- 14. 檔案格式
- 15. 加密服务
- 16. 通用操作系统服务
- 16.1.
os
— 操作系统接口模块 - 16.2.
io
— 处理流的核心工具 - 16.3.
time
— 时间的访问和转换 - 16.4.
argparse
— 命令行选项、参数和子命令解析器 - 16.5.
getopt
— C-style parser for command line options - 16.6. 模块
logging
— Python 的日志记录工具 - 16.7.
logging.config
— 日志记录配置 - 16.8.
logging.handlers
— 日志处理 - 16.9.
getpass
— 便携式密码输入工具 - 16.10.
curses
— 终端字符单元显示的处理 - 16.11.
curses.textpad
— Text input widget for curses programs - 16.12.
curses.ascii
— Utilities for ASCII characters - 16.13.
curses.panel
— A panel stack extension for curses - 16.14.
platform
— 获取底层平台的标识数据 - 16.15.
errno
— Standard errno system symbols - 16.16.
ctypes
— Python 的外部函数库
- 16.1.
- 17. 并发执行
- 18. Interprocess Communication and Networking
- 18.1.
socket
— 底层网络接口 - 18.2.
ssl
— TLS/SSL wrapper for socket objects - 18.3.
select
— Waiting for I/O 完成 - 18.4.
selectors
— 高级 I/O 复用库 - 18.5.
asyncio
— Asynchronous I/O, event loop, coroutines and tasks - 18.6.
asyncore
— 异步socket处理器 - 18.7.
asynchat
— 异步 socket 指令/响应 处理器 - 18.8.
signal
— 设置异步事件处理程序 - 18.9.
mmap
— 内存映射文件支持
- 18.1.
- 19. 互联网数据处理
- 19.1.
email
— 电子邮件与 MIME 处理包 - 19.2.
json
— JSON 编码和解码器 - 19.3.
mailcap
— Mailcap file handling - 19.4.
mailbox
— Manipulate mailboxes in various formats - 19.5.
mimetypes
— Map filenames to MIME types - 19.6.
base64
—— Base16、Base32、Base64、Base85 資料編碼 - 19.7.
binhex
— 对binhex4文件进行编码和解码 - 19.8.
binascii
— 二进制和 ASCII 码互转 - 19.9.
quopri
— 编码与解码经过 MIME 转码的可打印数据 - 19.10.
uu
— 对 uuencode 文件进行编码与解码
- 19.1.
- 20. 结构化标记处理工具
- 20.1.
html
— 超文本标记语言支持 - 20.2.
html.parser
— 简单的 HTML 和 XHTML 解析器 - 20.3.
html.entities
— HTML 一般实体的定义 - 20.4. XML 處理模組
- 20.5.
xml.etree.ElementTree
— ElementTree XML API - 20.6.
xml.dom
— The Document Object Model API - 20.7.
xml.dom.minidom
— Minimal DOM implementation - 20.8.
xml.dom.pulldom
— Support for building partial DOM trees - 20.9.
xml.sax
— Support for SAX2 parsers - 20.10.
xml.sax.handler
— Base classes for SAX handlers - 20.11.
xml.sax.saxutils
— SAX Utilities - 20.12.
xml.sax.xmlreader
— Interface for XML parsers - 20.13.
xml.parsers.expat
— Fast XML parsing using Expat
- 20.1.
- 21. 互联网协议和支持
- 21.1.
webbrowser
— 方便的Web浏览器控制器 - 21.2.
cgi
— Common Gateway Interface support - 21.3.
cgitb
— 用于 CGI 脚本的回溯管理器 - 21.4.
wsgiref
— WSGI Utilities and Reference Implementation - 21.5.
urllib
— URL 处理模块 - 21.6.
urllib.request
— 用于打开 URL 的可扩展库 - 21.7.
urllib.response
— urllib 使用的 Response 类 - 21.8.
urllib.parse
— Parse URLs into components - 21.9.
urllib.error
— urllib.request 引发的异常类 - 21.10.
urllib.robotparser
— robots.txt 语法分析程序 - 21.11.
http
— HTTP 模块 - 21.12.
http.client
— HTTP 协议客户端 - 21.13.
ftplib
— FTP 协议客户端 - 21.14.
poplib
— POP3 protocol client - 21.15.
imaplib
— IMAP4 protocol client - 21.16.
nntplib
— NNTP protocol client - 21.17.
smtplib
—SMTP协议客户端 - 21.18.
smtpd
— SMTP 服务器 - 21.19.
telnetlib
— Telnet client - 21.20.
uuid
— UUID objects according to RFC 4122 - 21.21.
socketserver
— A framework for network servers - 21.22.
http.server
— HTTP 服务器 - 21.23.
http.cookies
— HTTP状态管理 - 21.24.
http.cookiejar
—— HTTP 客户端的 Cookie 处理 - 21.25.
xmlrpc
— XMLRPC 服务端与客户端模块 - 21.26.
xmlrpc.client
— XML-RPC client access - 21.27.
xmlrpc.server
— Basic XML-RPC servers - 21.28.
ipaddress
— IPv4/IPv6 manipulation library
- 21.1.
- 22. 多媒体服务
- 22.1.
audioop
— Manipulate raw audio data - 22.2.
aifc
— Read and write AIFF and AIFC files - 22.3.
sunau
— 读写 Sun AU 文件 - 22.4.
wave
— 读写WAV格式文件 - 22.5.
chunk
— Read IFF chunked data - 22.6.
colorsys
— 颜色系统间的转换 - 22.7.
imghdr
— 推测图像类型 - 22.8.
sndhdr
— 推测声音文件的类型 - 22.9.
ossaudiodev
— Access to OSS-compatible audio devices
- 22.1.
- 23. 國際化
- 24. 程式框架
- 25. 以 Tk 打造 GUI
- 26. 開發工具
- 26.1.
typing
— 类型标注支持 - 26.2.
pydoc
— Documentation generator and online help system - 26.3.
doctest
— 测试交互性的Python示例 - 26.4.
unittest
— 單元測試框架 - 26.5.
unittest.mock
— 模拟对象库 - 26.6.
unittest.mock
上手指南 - 26.7. 2to3 - 自動將 Python 2的程式碼轉成 Python 3
- 26.8.
test
— Regression tests package for Python - 26.9.
test.support
— Utilities for the Python test suite
- 26.1.
- 27. 调试和分析
- 28. 軟體封裝與發布
- 29. Python运行时服务
- 29.1.
sys
— 系统相关的参数和函数 - 29.2.
sysconfig
— Provide access to Python’s configuration information - 29.3.
builtins
— 内建对象 - 29.4.
__main__
— 顶层脚本环境 - 29.5.
warnings
— Warning control - 29.6.
contextlib
— Utilities forwith
-statement contexts - 29.7.
abc
— 抽象基类 - 29.8.
atexit
— 退出处理器 - 29.9.
traceback
— 打印或检索堆栈回溯 - 29.10.
__future__
— Future 语句定义 - 29.11.
gc
— 垃圾回收器接口 - 29.12.
inspect
— 检查对象 - 29.13.
site
— Site-specific configuration hook - 29.14.
fpectl
— Floating point exception control
- 29.1.
- 30. 自定义 Python 解释器
- 31. 匯入模組
- 32. Python 语言服务
- 32.1.
parser
— Access Python parse trees - 32.2.
ast
— 抽象语法树 - 32.3.
symtable
— Access to the compiler’s symbol tables - 32.4.
symbol
— 与 Python 解析树一起使用的常量 - 32.5.
token
— 与Python解析树一起使用的常量 - 32.6.
keyword
— 检验Python关键字 - 32.7.
tokenize
— Tokenizer for Python source - 32.8.
tabnanny
— 模糊缩进检测 - 32.9.
pyclbr
— Python class browser support - 32.10.
py_compile
— Compile Python source files - 32.11.
compileall
— Byte-compile Python libraries - 32.12.
dis
— Python bytecode的反組譯器 - 32.13.
pickletools
— Tools for pickle developers
- 32.1.
- 33. 杂项服务
- 34. Windows系统相关模块
- 35. Unix 专有服务
- 35.1.
posix
— The most common POSIX system calls - 35.2.
pwd
— 用户密码数据库 - 35.3.
spwd
— The shadow password database - 35.4.
grp
— The group database - 35.5.
crypt
— Function to check Unix passwords - 35.6.
termios
— POSIX style tty control - 35.7.
tty
— 终端控制功能 - 35.8.
pty
— Pseudo-terminal utilities - 35.9.
fcntl
— Thefcntl
andioctl
system calls - 35.10.
pipes
— Interface to shell pipelines - 35.11.
resource
— Resource usage information - 35.12.
nis
— Interface to Sun’s NIS (Yellow Pages) - 35.13. Unix syslog 库例程
- 35.1.
- 36. 被取代的模块
- 37. 未创建文档的模块