Python 標準函式庫 (Standard Library)¶
Python 語言參考手冊說明 Python 這門語言確切的文法及語意,而這份函式庫參考手冊則是說明隨著 Python 一起發佈的標準函式庫,除此之外,其內容也包含一些時常出現在 Python 發佈版本中的非必要套件。
Python 的標準函式庫是非常龐大的,其提供了如下所述極多且涵蓋用途極廣的許多模組。包含一些用 C 語言撰寫,可以操作像是檔案讀寫等系統相關功能的內建模組,當然也有用 Python 撰寫,並使用標準解法解決許多常見問題的模組。其中有些模組則是特別針對 Python 的可攜性去設計的,為此特地將一些平台特殊相依性的功能抽象化成可跨平台的 API。
Python 的 Windows 安裝檔基本上包含整個標準函式庫,且通常也包含許多附加的組件;而在類 Unix 作業系統方面,Python 通常是以一系列的套件被安裝,因此對於某些或全部的可選組件,可能都必須使用該作業系統提供的套件管理工具來安裝。
在標準函式庫之外,還有成千上萬且不斷增加的組件(從個別的程式、模組、套件到完整的應用程式開發框架),可以從 Python 套件索引 (Python Package Index) 中取得。
- 簡介
- 內建函式
- 內建常數
- 內建型別
- 真值檢測
- Boolean Operations ---
and
,or
,not
- Comparisons
- Numeric Types ---
int
,float
,complex
- 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
--- Common string operationsre
--- 正規表示式 (regular expression) 操作difflib
--- Helpers for computing deltastextwrap
--- Text wrapping and fillingunicodedata
--- Unicode Databasestringprep
--- Internet String Preparationreadline
--- GNU readline interfacerlcompleter
--- Completion function for GNU readline
- Binary Data Services
- 資料型別
datetime
--- 日期與時間的基本型別zoneinfo
--- IANA 時區支援calendar
--- General calendar-related functionscollections
--- 容器資料型態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
--- Support for enumerationsgraphlib
—-- 使用類圖 (graph-like) 結構進行操作的功能
- 數值與數學模組
- 函式編程模組
- 檔案與目錄存取
pathlib
--- Object-oriented filesystem pathsos.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
--- Logging facility for Pythonlogging.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
--- Shared memory for direct access across processes- The
concurrent
package 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
--- HyperText Markup Language supporthtml.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 and Support
webbrowser
--- Convenient web-browser controllerwsgiref
--- WSGI Utilities and Reference Implementationurllib
--- 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
--- UUID objects according to RFC 4122socketserver
--- A framework for network servershttp.server
--- HTTP servershttp.cookies
--- HTTP state managementhttp.cookiejar
--- Cookie handling for HTTP clientsxmlrpc
--- XMLRPC server and client modulesxmlrpc.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
--- Support for type hintspydoc
--- Documentation generator and online help system- Python Development Mode
doctest
--- Test interactive Python examplesunittest
--- 單元測試框架unittest.mock
--- mock object libraryunittest.mock
--- getting started- 2to3 --- 自動將 Python 2的程式碼轉成 Python 3
test
--- Regression tests package for Pythontest.support
--- Utilities for the Python test suitetest.support.socket_helper
--- Utilities for socket teststest.support.script_helper
--- Utilities for the Python execution teststest.support.bytecode_helper
--- Support tools for testing correct bytecode generationtest.support.threading_helper
--- Utilities for threading teststest.support.os_helper
--- Utilities for os teststest.support.import_helper
--- Utilities for import teststest.support.warnings_helper
--- Utilities for warnings tests
- 除錯與效能分析
- 軟體封裝與發布
- Python Runtime Services
sys
--- 系統特定的參數與函式sysconfig
--- Provide access to Python's configuration informationbuiltins
--- 內建物件__main__
--- Top-level code environmentwarnings
--- Warning controldataclasses
--- Data Classescontextlib
--- Utilities forwith
-statement contextsabc
--- 抽象基底類別atexit
--- Exit handlerstraceback
--- Print or retrieve a stack traceback__future__
--- Future statement definitionsgc
--- 垃圾回收器介面 (Garbage Collector interface)inspect
--- Inspect live objectssite
--- 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
--- The implementation ofimport
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 Treessymtable
--- Access to the compiler's symbol tablestoken
--- Constants used with Python parse treeskeyword
--- 檢驗 Python 關鍵字tokenize
--- Tokenizer for Python sourcetabnanny
--- 偵測不良縮排pyclbr
--- Python module browser supportpy_compile
--- Compile Python source filescompileall
--- Byte-compile Python librariesdis
--- Python bytecode的反組譯器pickletools
--- Tools for pickle developers
- MS Windows 特有服務
- Unix 特有服務
- Modules command-line interface (CLI)
- 已被取代的模組
aifc
--- 讀寫 AIFF 與 AIFC 檔案asynchat
--- 非同步 socket 指令/回應處理函式asyncore
--- 非同步 socket 處理函式audioop
--- 操作原始聲音檔案cgi
--- 通用閘道器介面支援cgitb
--- CGI 腳本的回溯 (traceback) 管理程式chunk
--- 讀取 IFF 分塊資料crypt
--- 用於檢查 Unix 密碼的函式imghdr
--- 推測圖片種類imp
--- Access the import internalsmailcap
--- Mailcap file handlingmsilib
--- 讀寫 Microsoft Installer 檔案nis
--- Sun NIS (Yellow Pages) 介面nntplib
--- NNTP 協定客戶端optparse
--- Parser for command line optionsossaudiodev
--- 對 OSS 相容聲音裝置的存取pipes
--- shell pipelines 介面smtpd
--- SMTP 伺服器sndhdr
--- 判定聲音檔案的型別spwd
--- shadow 密碼資料庫sunau
--- 讀寫 Sun AU 檔案telnetlib
--- Telnet 客戶端xdrlib
--- uuencode 檔案的編碼與解碼xdrlib
--- XDR 資料的編碼與解碼
- Security Considerations