Python 標準函式庫 (Standard Library)¶
Python 語言參考手冊說明 Python 這門語言確切的文法及語意,而這份函式庫參考手冊則是說明隨著 Python 一起發佈的標準函式庫,除此之外,其內容也包含一些時常出現在 Python 發佈版本中的非必要套件。
Python 的標準函式庫是非常龐大的,其提供了如下所述極多且涵蓋用途極廣的許多模組。包含一些用 C 語言撰寫,可以操作像是檔案讀寫等系統相關功能的內建模組,當然也有用 Python 撰寫,並使用標準解法解決許多常見問題的模組。其中有些模組則是特別針對 Python 的可攜性去設計的,為此特地將一些平台特殊相依性的功能抽象化成可跨平台的 API。
Python 的 Windows 安裝檔基本上包含整個標準函式庫,且通常也包含許多附加的組件;而在類 Unix 作業系統方面,Python 通常是以一系列的套件被安裝,因此對於某些或全部的可選組件,可能都必須使用該作業系統提供的套件管理工具來安裝。
在標準函式庫之外,還有成千上萬且不斷增加的組件(從個別的程式、模組、套件到完整的應用程式開發框架),可以從 Python 套件索引 (Python Package Index) 中取得。
- 簡介
- 內建函式
abs()
aiter()
all()
anext()
any()
ascii()
bin()
bool
breakpoint()
callable()
chr()
classmethod()
compile()
complex
delattr()
dir()
divmod()
enumerate()
eval()
exec()
filter()
float
format()
getattr()
globals()
hasattr()
hash()
help()
hex()
id()
input()
int
isinstance()
issubclass()
iter()
len()
locals()
map()
max()
min()
next()
object
oct()
open()
ord()
pow()
print()
property
repr()
reversed()
round()
setattr()
slice
sorted()
staticmethod()
sum()
super
type
vars()
zip()
__import__()
- 內建常數
- 內建型別
- 真值檢測
- Boolean(布林)運算 ---
and
,or
,not
- 比較運算
- Numeric Types ---
int
,float
,complex
- Boolean Type -
bool
- Iterator Types
- Sequence Types ---
list
,tuple
,range
- Text Sequence Type ---
str
- Binary Sequence Types ---
bytes
,bytearray
,memoryview
- Set Types ---
set
,frozenset
- Mapping Types ---
dict
- Context Manager Types
- Type Annotation Types --- Generic Alias, Union
- Other Built-in Types
- Special Attributes
- Integer string conversion length limitation
- 內建的例外
- 文本處理 (Text Processing) 服務
string
--- 常見的字串操作re
--- 正規表示式 (regular expression) 操作difflib
--- Helpers for computing deltastextwrap
--- Text wrapping and fillingunicodedata
--- Unicode Databasestringprep
--- Internet String Preparationreadline
--- GNU readline interfacerlcompleter
--- Completion function for GNU readline
- 二進位資料服務
- 資料型別
datetime
--- 日期與時間的基本型別zoneinfo
--- IANA 時區支援calendar
--- 日曆相關函式collections
--- 容器資料型態collections.abc
--- Abstract Base Classes for Containersheapq
--- 堆積佇列 (heap queue) 演算法bisect
--- 陣列二分演算法 (Array bisection algorithm)array
--- 高效率的數值型陣列weakref
--- Weak referencestypes
--- Dynamic type creation and names for built-in typescopy
--- 淺層 (shallow) 和深層 (deep) 複製操作pprint
--- Data pretty printerreprlib
--- Alternaterepr()
implementationenum
--- 對列舉的支援graphlib
—-- 使用類圖 (graph-like) 結構進行操作的功能
- 數值與數學模組
- 函式編程模組
- 檔案與目錄存取
pathlib
--- 物件導向檔案系統路徑os.path
--- 常見的路徑名操作fileinput
--- Iterate over lines from multiple input streamsstat
--- Interpretingstat()
resultsfilecmp
--- File and Directory Comparisonstempfile
--- 生成臨時檔案和目錄glob
--- Unix 風格的路徑名稱模式擴展fnmatch
--- Unix filename pattern matchinglinecache
--- Random access to text linesshutil
--- High-level file operations
- Data Persistence
- 資料壓縮與保存
- 檔案格式
- 加密服務
- 通用作業系統服務
os
--- 各種作業系統介面io
— 處理資料串流的核心工具time
--- Time access and conversionsargparse
--- Parser for command-line options, arguments and sub-commandsgetopt
--- C-style parser for command line optionslogging
--- Python 的日誌記錄工具logging.config
--- Logging configurationlogging.handlers
--- Logging handlersgetpass
--- 可攜式密碼輸入工具curses
--- Terminal handling for character-cell displayscurses.textpad
--- Text input widget for curses programscurses.ascii
--- ASCII 字元的工具程式curses.panel
--- A panel stack extension for cursesplatform
--- 獲取底層平臺的標識資料errno
--- Standard errno system symbolsctypes
--- A foreign function library for Python
- 並行執行 (Concurrent Execution)
threading
--- Thread-based parallelismmultiprocessing
--- Process-based parallelismmultiprocessing.shared_memory
--- 對於共享記憶體的跨行程直接存取concurrent
套件concurrent.futures
-- 啟動平行任務subprocess
--- Subprocess managementsched
--- Event schedulerqueue
--- 同步佇列 (queue) class(類別)contextvars
--- Context Variables_thread
--- Low-level threading API
- Networking and Interprocess Communication
- 網際網路資料處理
- Structured Markup Processing Tools
html
--- 超連結標記語言 (HTML) 支援html.parser
--- 簡單的 HTML 和 XHTML 剖析器html.entities
--- HTML 一般實體的定義- XML 處理模組
xml.etree.ElementTree
--- The 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
- 網路協定 (Internet protocols) 及支援
webbrowser
--- Convenient web-browser controllerwsgiref
--- WSGI 工具與參考實作urllib
--- URL 處理模組urllib.request
--- 用來開啟 URLs 的可擴充函式庫urllib.response
--- Response classes used by urlliburllib.parse
--- Parse URLs into componentsurllib.error
--- urllib.request 引發的例外類別urllib.robotparser
--- robots.txt 的剖析器http
--- HTTP 模組http.client
--- HTTP protocol clientftplib
--- FTP 協定用戶端poplib
--- POP3 protocol clientimaplib
--- IMAP4 protocol clientsmtplib
--- SMTP protocol clientuuid
--- RFC 4122 定義的 UUID 物件socketserver
--- A framework for network servershttp.server
--- HTTP servershttp.cookies
--- HTTP state managementhttp.cookiejar
--- Cookie handling for HTTP clientsxmlrpc
--- XMLRPC 伺服器與用戶模組xmlrpc.client
--- XML-RPC client accessxmlrpc.server
--- Basic XML-RPC serversipaddress
--- IPv4/IPv6 manipulation library
- 多媒體服務
- 國際化
- 程式框架
- 以 Tk 打造圖形使用者介面 (Graphical User Interfaces)
tkinter
--- Python interface to Tcl/Tktkinter.colorchooser
--- Color choosing dialogtkinter.font
--- Tkinter font wrapper- Tkinter Dialogs
tkinter.messagebox
--- Tkinter message promptstkinter.scrolledtext
--- Scrolled Text Widgettkinter.dnd
--- Drag and drop supporttkinter.ttk
--- Tk themed widgetstkinter.tix
--- Tk 擴充小工具- IDLE
- 開發工具
typing
--- 支援型別提示pydoc
--- Documentation generator and online help system- Python Development Mode
doctest
--- Test interactive Python examplesunittest
--- 單元測試框架unittest.mock
— mock 物件函式庫unittest.mock
--- 入門指南- 2to3 --- 自動將 Python 2的程式碼轉成 Python 3
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
--- Utilities for threading teststest.support.os_helper
--- 用於 os 測試的工具test.support.import_helper
--- 用於 import 測試的工具test.support.warnings_helper
--- 用於 warnings 測試的工具
- 除錯與效能分析
- 軟體封裝與發布
- Python Runtime Services
sys
--- 系統特定的參數與函式sys.monitoring
--- Execution event monitoringsysconfig
--- Provide access to Python's configuration informationbuiltins
--- 內建物件__main__
--- 頂層程式碼環境warnings
--- Warning controldataclasses
--- Data Classescontextlib
--- Utilities forwith
-statement contextsabc
--- 抽象基底類別atexit
--- Exit handlerstraceback
--- Print or retrieve a stack traceback__future__
--- Future 陳述式定義gc
--- 垃圾回收器介面 (Garbage Collector interface)inspect
--- 檢視活動物件site
--- Site-specific configuration hook
- Custom Python Interpreters
- 引入模組
zipimport
--- Import modules from Zip archivespkgutil
--- Package extension utilitymodulefinder
--- Find modules used by a scriptrunpy
--- Locating and executing Python modulesimportlib
---import
的實作importlib.resources
-- Package resource reading, opening and accessimportlib.resources.abc
-- Abstract base classes for resourcesimportlib.metadata
-- Accessing package metadata- The initialization of the
sys.path
module search path
- Python Language Services
ast
--- 抽象語法樹 (Abstract Syntax Trees)symtable
--- 存取編譯器的符號表token
--- Constants used with Python parse treeskeyword
--- 檢驗 Python 關鍵字tokenize
--- Tokenizer for Python sourcetabnanny
--- 偵測不良縮排pyclbr
--- Python module browser supportpy_compile
— 編譯 Python 來源檔案compileall
--- Byte-compile Python librariesdis
--- Python bytecode的反組譯器pickletools
--- pickle 開發者的工具
- MS Windows 特有服務
- Unix 特有服務
- 模組命令列介面
- 已被取代的模組
aifc
--- 讀寫 AIFF 與 AIFC 檔案audioop
--- 操作原始聲音檔案cgi
--- 通用閘道器介面支援cgitb
--- CGI 腳本的回溯 (traceback) 管理程式chunk
--- 讀取 IFF 分塊資料crypt
--- 用於檢查 Unix 密碼的函式imghdr
--- 推測圖片種類mailcap
--- Mailcap file handlingmsilib
--- 讀寫 Microsoft Installer 檔案nis
--- Sun NIS (Yellow Pages) 介面nntplib
--- NNTP 協定客戶端optparse
--- Parser for command line optionsossaudiodev
--- 對 OSS 相容聲音裝置的存取pipes
--- shell pipelines 介面sndhdr
--- 判定聲音檔案的型別spwd
--- shadow 密碼資料庫sunau
--- 讀寫 Sun AU 檔案telnetlib
--- Telnet 客戶端xdrlib
--- uuencode 檔案的編碼與解碼xdrlib
--- XDR 資料的編碼與解碼
- 安全性注意事項