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) 服務
- 二進位資料服務
- 資料型別
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) 結構進行操作的功能
- 數值與數學模組
- 函式程式設計模組
- 檔案與目錄存取
- 資料持久性 (Data Persistence)
- 資料壓縮與保存
- 檔案格式
- 加密服務
- 通用作業系統服務
- 命令列介面函式庫
- 並行執行 (Concurrent Execution)
threading--- 執行緒層級的平行處理multiprocessing--- 以行程為基礎的平行性multiprocessing.shared_memory--- 對於共享記憶體的跨行程直接存取concurrent套件concurrent.futures--- 啟動平行任務concurrent.interpreters--- 在同一個行程中使用多個直譯器subprocess--- 子行程管理sched--- 事件排程器queue--- 同步佇列 (synchronized queue) 類別contextvars--- 情境變數_thread--- 低階執行緒 API
- 網路與行程間通訊
- 網際網路資料處理
- 結構化標記處理工具
html--- 超文本標記語言 (HTML) 支援html.parser--- 簡單的 HTML 和 XHTML 剖析器html.entities--- HTML 一般實體的定義- XML 處理模組
xml.etree.cElementTree--- ElementTree XML APIxml.dom--- Document 物件模型 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 剖析
- 網路協定 (Internet protocols) 及支援
webbrowser--- 方便的網頁瀏覽器控制器wsgiref--- WSGI 工具與參考實作urllib--- URL 處理模組urllib.request--- 用來開啟 URLs 的可擴充函式庫urllib.response--- Response classes used by urlliburllib.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 打造圖形使用者介面 (Graphical User Interfaces)
- 開發工具
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 測試的工具
- 除錯與效能分析
- 軟體封裝與發布
- Python Runtime 服務
sys--- 系統特定的參數與函式sys.monitoring--- 執行事件監控sysconfig--- 提供 Python 設定資訊的存取builtins--- 內建物件__main__--- 頂層程式碼環境warnings--- 警告控制dataclasses--- Data Classescontextlib---with陳述式工具程式abc--- 抽象基底類別atexit--- 退出處理函式traceback--- 列印或取得堆疊回溯 (stack traceback)__future__--- Future 陳述式定義gc--- 垃圾回收器介面 (Garbage Collector interface)inspect--- 檢視活動物件annotationlib--- 用於自我檢查註釋的功能site--- Site-specific configuration hook
- 自訂 Python 直譯器
- 引入模組
- Python 語言服務
ast--- 抽象語法樹 (Abstract Syntax Trees)symtable--- 存取編譯器的符號表token--- 與 Python 剖析樹一起使用的常數keyword--- 檢驗 Python 關鍵字tokenize--- Tokenizer for Python sourcetabnanny--- 偵測不良縮排pyclbr--- Python 模組瀏覽器支援py_compile— 編譯 Python 來源檔案compileall--- 位元組編譯 Python 函式庫dis--- Python bytecode 的反組譯器pickletools--- pickle 開發者的工具
- MS Windows 特有服務
- Unix 特有服務
- 模組命令列介面
- 已被取代的模組
- 已移除的模組
- 安全性注意事項