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.

Python 的 Windows 安裝檔基本上包含整個標準函式庫，且通常也包含許多附加
的組件；而在類 Unix 作業系統方面，Python 通常是以一系列的套件被安裝，
因此對於某些或全部的可選組件，可能都必須使用該作業系統提供的套件管理工
具來安裝。

在標準函式庫之外，還有成千上萬且不斷增加的組件（從個別的程式、模組、套
件到完整的應用程式開發框架），可以從 Python 套件索引 (Python Package
Index) 中取得。

* 簡介

  * 可用性之標註

* 文本處理 (Text Processing) 服務

  * "string" --- 常見的字串操作

  * "string.templatelib" --- 對模板字串字面值的支援

  * "re" --- 正規表示式 (regular expression) 操作

  * "difflib" --- 計算差異的輔助工具

  * "textwrap" --- 文字包裝與填充

  * "unicodedata" --- Unicode 資料庫

  * "stringprep" --- 網際網路字串的準備

  * "readline" --- GNU readline 介面

  * "rlcompleter" --- GNU readline 的補全函式

* 二進位資料服務

  * "struct" --- 將位元組直譯為打包起來的二進位資料

  * "codecs" --- 編解碼器註冊表和基底類別

* 資料型別

  * "datetime" --- 日期與時間的基本型別

  * "zoneinfo" --- IANA 時區支援

  * "calendar" --- 日曆相關函式

  * "collections" --- 容器資料型別

  * "collections.abc" --- 容器的抽象基底類別

  * "heapq" --- 堆積佇列 (heap queue) 演算法

  * "bisect" --- 陣列二分演算法 (Array bisection algorithm)

  * "array" --- 高效率的數值型陣列

  * "weakref" --- 弱參照

  * "types" --- 動態型別建立與內建型別名稱

  * "copy" --- 淺層 (shallow) 和深層 (deep) 複製操作

  * "pprint" --- 資料美化列印器

  * "reprlib" --- "repr()" 的替代實作

  * "enum" --- 對列舉的支援

  * "graphlib" —-- 使用類圖 (graph-like) 結構進行操作的功能

* 數值與數學模組

  * "numbers" --- 數值的抽象基底類別

  * "math" --- 數學函式

  * "math.integer" --- integer-specific mathematics functions

  * "cmath" --- 複數的數學函式

  * "decimal" --- 十進位固定點和浮點運算

  * "fractions" --- 有理數

  * "random" --- 產生偽隨機數

  * "statistics" --- 數學統計函式

* 函式程式設計模組

  * "itertools" --- 建立產生高效率迴圈之疊代器的函式

  * "functools" --- 可呼叫物件上的高階函式與操作

  * "operator" --- 標準運算子替代函式

* 檔案與目錄存取

  * "pathlib" --- 物件導向檔案系統路徑

  * "os.path" --- 常見的路徑名操作

  * "stat" --- 直譯 "stat()" 的結果

  * "filecmp" --- 檔案與目錄比較

  * "tempfile" --- 生成臨時檔案和目錄

  * "glob" --- Unix 風格的路徑名稱模式擴展

  * "fnmatch" --- Unix 檔案名稱模式比對

  * "linecache" --- 隨機存取文字列

  * "shutil" — 高階檔案操作

* 資料持久性 (Data Persistence)

  * "pickle" --- Python 物件序列化

  * "copyreg" --- 註冊 "pickle" 支援函式

  * "shelve" --- Python object persistence

  * "marshal" --- 內部 Python 物件序列化

  * "dbm" --- Unix "databases" 的介面

  * "sqlite3" --- SQLite 資料庫的 DB-API 2.0 介面

* 資料壓縮與保存

  * "compression" 套件

  * "compression.zstd" --- 與 Zstandard 格式相容的壓縮

  * "zlib" --- 相容於 **gzip** 的壓縮

  * "gzip" --- **gzip** 檔案的支援

  * "bz2" --- **bzip2** 壓縮的支援

  * "lzma" --- 使用 LZMA 演算法進行壓縮

  * "zipfile" --- 處理 ZIP 封存檔案

  * "tarfile" --- 讀取與寫入 tar 封存檔案

* 檔案格式

  * "csv" --- CSV file reading and writing

  * "configparser" --- 設定檔剖析器

  * "tomllib" --- 剖析 TOML 檔案

  * "netrc" --- netrc 檔案處理

  * "plistlib" --- 產生和剖析 Apple ".plist" 檔案

* 加密服務

  * "hashlib" --- 安全雜湊與訊息摘要

  * "hmac" --- 基於金鑰雜湊的訊息驗證

  * "secrets" --- 產生用於管理機密的安全亂數

* 通用作業系統服務

  * "os" --- 各種作業系統介面

  * "io" — 處理資料串流的核心工具

  * "time" --- 時間存取與轉換

  * "logging" --- Python 的日誌記錄工具

  * "logging.config" --- 日誌記錄配置

  * "logging.handlers" --- 日誌紀錄處理器

  * "platform" ---  對底層平臺識別資料的存取

  * "errno" --- 標準 errno 系統符號

  * "ctypes" --- 用於 Python 的外部函式庫

* 命令列介面函式庫

  * "argparse" --- 命令列選項、引數和子命令的剖析器

  * "optparse" --- 命令列選項剖析器

  * "getpass" --- 可攜式密碼輸入工具

  * "fileinput" --- 逐列疊代多個輸入串流

  * "curses" --- 字元儲存格顯示的終端處理

  * "curses.textpad" --- Text input widget for curses programs

  * "curses.ascii" --- ASCII 字元的工具程式

  * "curses.panel" --- curses 的面板堆疊擴充

  * "cmd" --- 以列為導向的命令直譯器支援

* 並行執行 (Concurrent Execution)

  * "threading" --- 執行緒層級的平行處理

  * "multiprocessing" --- 以行程為基礎的平行性

  * "multiprocessing.shared_memory" --- 對於共享記憶體的跨行程直接存取

  * "concurrent" 套件

  * "concurrent.futures" --- 啟動平行任務

  * "concurrent.interpreters" --- 在同一個行程中使用多個直譯器

  * "subprocess" --- 子行程管理

  * "sched" --- 事件排程器

  * "queue" --- 同步佇列 (synchronized queue) 類別

  * "contextvars" --- 情境變數

  * "_thread" --- 低階執行緒 API

* 網路與行程間通訊

  * "asyncio" --- 非同步 I/O

  * "socket" — 低階網路介面

  * "ssl" --- socket 物件的 TLS/SSL 包裝器

  * "select" --- 等待 I/O 完成

  * "selectors" --- 高階 I/O 多工

  * "signal" --- 設定非同步事件的處理函式

  * "mmap" --- 記憶體對映檔案的支援

* 網際網路資料處理

  * "email" --- 郵件和 MIME 處理套件

  * "json" --- JSON 編碼器與解碼器

  * "mailbox" --- 以各種格式操作郵件信箱

  * "mimetypes" --- 將檔案名稱對映到 MIME 類型

  * "base64" --- Base16、Base32、Base64、Base85 資料編碼

  * "binascii" --- 在二進位制和 ASCII 之間轉換

  * "quopri" --- 編碼和解碼 MIME 可列印字元資料

* 結構化標記處理工具

  * "html" --- 超文本標記語言 (HTML) 支援

  * "html.parser" --- 簡單的 HTML 和 XHTML 剖析器

  * "html.entities" --- HTML 一般實體的定義

  * XML 處理模組

  * "xml.etree.cElementTree" --- ElementTree XML API

  * "xml.dom" --- Document 物件模型 API

  * "xml.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 剖析

* 網路協定 (Internet protocols) 及支援

  * "webbrowser" --- 方便的網頁瀏覽器控制器

  * "wsgiref" --- WSGI 工具與參考實作

  * "urllib" --- URL 處理模組

  * "urllib.request" --- 用來開啟 URLs 的可擴充函式庫

  * "urllib.response" --- Response classes used by 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 操作函式庫

* 多媒體服務

  * "wave" --- 讀寫 WAV 檔案

  * "colorsys" --- 顏色系統間的轉換

* 國際化

  * "gettext" --- 多語言國際化服務

  * "locale" --- 國際化服務

* 以 Tk 打造圖形使用者介面 (Graphical User Interfaces)

  * "tkinter" --- Tcl/Tk 的 Python 介面

  * "tkinter.colorchooser" --- 顏色選擇對話框

  * "tkinter.font" --- Tkinter 字型包裝器

  * Tkinter dialogs

  * "tkinter.messagebox" --- Tkinter 訊息提示

  * "tkinter.scrolledtext" --- Scrolled text widget

  * "tkinter.dnd" --- 拖放支援

  * "tkinter.ttk" --- Tk 主題化小工具

  * IDLE --- Python 編輯器與 shell

  * "turtle" --- 龜圖學 (Turtle graphics)

* 開發工具

  * "typing" --- 支援型別提示

  * "pydoc" --- 文件產生器與線上幫助系統

  * Python 開發模式

  * "doctest" --- 測試互動式 Python 範例

  * "unittest" --- 單元測試框架

  * "unittest.mock" — mock 物件函式庫

  * "unittest.mock" --- 入門指南

  * "test" --- Python 的回歸測試 (regression tests) 套件

  * "test.support" --- Python 測試套件的工具

  * "test.support.socket_helper" --- 用於 socket 測試的工具

  * "test.support.script_helper" --- 用於 Python 執行測試的工具

  * "test.support.bytecode_helper" --- 用於測試位元組碼能正確產生的支
    援工具

  * "test.support.threading_helper" --- 用於 threading 測試的工具

  * "test.support.os_helper" --- 用於 os 測試的工具

  * "test.support.import_helper" --- 用於 import 測試的工具

  * "test.support.warnings_helper" --- 用於 warnings 測試的工具

* Debugging and profiling

  * 稽核事件表

  * "bdb" --- 偵錯器框架

  * "faulthandler" --- 傾印 Python 回溯

  * "pdb" --- Python 偵錯器

  * "profiling" --- Python profilers

  * "pstats" --- Statistics for profilers

  * "timeit" --- 測量小量程式片段的執行時間

  * "trace" --- 追蹤或追查 Python 陳述式執行

  * "tracemalloc" --- 追蹤記憶體配置

* 軟體封裝與發布

  * "ensurepip" --- "pip" 安裝器的初始建置 (bootstrapping)

  * "venv" --- 建立虛擬環境

  * "zipapp" —-- 管理可執行的 Python zip 封存檔案

* Python Runtime 服務

  * "sys" --- 系統特定的參數與函式

  * "sys.monitoring" --- 執行事件監控

  * "sysconfig" --- 提供 Python 設定資訊的存取

  * "builtins" --- 內建物件

  * "__main__" --- 頂層程式碼環境

  * "warnings" --- 警告控制

  * "dataclasses" --- Data Classes

  * "contextlib" --- "with" 陳述式工具程式

  * "abc" --- 抽象基底類別

  * "atexit" --- 退出處理函式

  * "traceback" --- 列印或取得堆疊回溯 (stack traceback)

  * "__future__" --- Future 陳述式定義

  * "gc" --- 垃圾回收器介面 (Garbage Collector interface)

  * "inspect" --- 檢視活動物件

  * "annotationlib" --- 用於自我檢查註釋的功能

  * "site" --- Site-specific configuration hook

* 自訂 Python 直譯器

  * "code" --- 直譯器基底類別

  * "codeop" --- 編譯 Python 程式碼

* 引入模組

  * "zipimport" --- 從 Zip 封存檔案匯入模組

  * "pkgutil" --- 套件擴充工具程式

  * "modulefinder" --- 搜尋腳本所使用的模組

  * "runpy" --- 定位並執行 Python 模組

  * "importlib" --- "import" 的實作

  * "importlib.resources" -- 套件資源的讀取、開啟與存取

  * "importlib.resources.abc" -- 資源的抽象基底類別

  * "importlib.metadata" -- 存取套件的元資料

  * "sys.path" 模組搜尋路徑的初始化

* Python 語言服務

  * "ast" --- 抽象語法樹 (Abstract Syntax Trees)

  * "symtable" --- 存取編譯器的符號表

  * "token" --- 與 Python 剖析樹一起使用的常數

  * "keyword" --- 檢驗 Python 關鍵字

  * "tokenize" --- Tokenizer for Python source

  * "tabnanny" --- 偵測不良縮排

  * "pyclbr" --- Python 模組瀏覽器支援

  * "py_compile" — 編譯 Python 來源檔案

  * "compileall" --- 位元組編譯 Python 函式庫

  * "dis" --- Python bytecode 的反組譯器

  * "pickletools" --- pickle 開發者的工具

* MS Windows 特有服務

  * "msvcrt" --- MS VC++ runtime 提供的有用例程

  * "winreg" --- Windows 註冊表存取

  * "winsound" --- Windows 的音效播放介面

* Unix 特有服務

  * "shlex" --- 簡單的語法分析

  * "posix" --- 最常見的 POSIX 系統呼叫

  * "pwd" --- 密碼資料庫

  * "grp" --- 群組資料庫

  * "termios" --- POSIX 風格 tty 控制

  * "tty" --- 終端機控制函式

  * "pty" --- 偽終端工具

  * "fcntl" --- "fcntl" 和 "ioctl" 系統呼叫

  * "resource" --- 資源使用資訊

  * "syslog" --- Unix syslog 函式庫例程

* 模組命令列介面

* Superseded modules

  * "getopt" --- 用於命令列選項的 C 風格剖析器

  * "profile" --- Pure Python profiler

* 已移除的模組

* 安全性注意事項
