Python 標準函式庫 (Standard Library)
************************************

Python 語言參考手冊說明 Python 這門語言確切的文法及語意，而這份函式庫
參考手冊則是說明隨著 Python 一起發佈的標準函式庫，除此之外，其內容也包
含一些時常出現在 Python 發佈版本中的非必要套件。

Python 的標準函式庫是非常龐大的，其提供了如下所述極多且涵蓋用途極廣的
許多模組。包含一些用 C 語言撰寫，可以操作像是檔案讀寫等系統相關功能的
內建模組，當然也有用 Python 撰寫，並使用標準解法解決許多常見問題的模組
。其中有些模組則是特別針對 Python 的可攜性去設計的，為此特地將一些平台
特殊相依性的功能抽象化成可跨平台的 API。

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

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

* 簡介

  * 可用性之註釋

* 內建函式

* 內建常數

  * 由 "site" module（模組）所添增的常數

* 內建型別

  * 真值檢測

  * 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

* 內建的例外

  * Exception context

  * 繼承自內建的例外

  * Base classes

  * Concrete exceptions

  * 警告

  * Exception groups

  * Exception hierarchy

* 文本處理 (Text Processing) 服務

  * "string" --- Common string operations

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

  * "difflib" --- Helpers for computing deltas

  * "textwrap" --- Text wrapping and filling

  * "unicodedata" --- Unicode Database

  * "stringprep" --- Internet String Preparation

  * "readline" --- GNU readline interface

  * "rlcompleter" --- Completion function for GNU readline

* Binary Data Services

  * "struct" --- Interpret bytes as packed binary data

  * "codecs" --- Codec registry and base classes

* 資料型別

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

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

  * "calendar" --- General calendar-related functions

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

  * "collections.abc" --- Abstract Base Classes for Containers

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

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

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

  * "weakref" --- Weak references

  * "types" --- Dynamic type creation and names for built-in types

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

  * "pprint" --- Data pretty printer

  * "reprlib" --- Alternate "repr()" implementation

  * "enum" --- Support for enumerations

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

* 數值與數學模組

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

  * "math" --- 數學函式

  * "cmath" --- Mathematical functions for complex numbers

  * "decimal" --- Decimal fixed point and floating point arithmetic

  * "fractions" --- Rational numbers

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

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

* 函式編程模組

  * "itertools" --- Functions creating iterators for efficient looping

  * "functools" --- Higher-order functions and operations on callable
    objects

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

* 檔案與目錄存取

  * "pathlib" --- Object-oriented filesystem paths

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

  * "fileinput" --- Iterate over lines from multiple input streams

  * "stat" --- Interpreting "stat()" results

  * "filecmp" --- File and Directory Comparisons

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

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

  * "fnmatch" --- Unix filename pattern matching

  * "linecache" --- Random access to text lines

  * "shutil" --- High-level file operations

* Data Persistence

  * "pickle" --- Python object serialization

  * "copyreg" --- Register "pickle" support functions

  * "shelve" --- Python object persistence

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

  * "dbm" --- Interfaces to Unix "databases"

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

* 資料壓縮與保存

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

  * "gzip" --- Support for **gzip** files

  * "bz2" --- Support for **bzip2** compression

  * "lzma" --- Compression using the LZMA algorithm

  * "zipfile" --- Work with ZIP archives

  * "tarfile" --- Read and write tar archive files

* 檔案格式

  * "csv" --- CSV File Reading and Writing

  * "configparser" --- Configuration file parser

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

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

  * "plistlib" --- Generate and parse Apple ".plist" files

* 加密服務

  * "hashlib" --- Secure hashes and message digests

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

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

* 通用作業系統服務

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

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

  * "time" --- Time access and conversions

  * "argparse" --- Parser for command-line options, arguments and sub-
    commands

  * "getopt" --- C-style parser for command line options

  * "logging" --- Logging facility for Python

  * "logging.config" --- Logging configuration

  * "logging.handlers" --- Logging handlers

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

  * "curses" --- Terminal handling for character-cell displays

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

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

  * "curses.panel" --- A panel stack extension for curses

  * "platform" ---  獲取底層平臺的標識資料

  * "errno" --- Standard errno system symbols

  * "ctypes" --- A foreign function library for Python

* 並行執行 (Concurrent Execution)

  * "threading" --- Thread-based parallelism

  * "multiprocessing" --- Process-based parallelism

  * "multiprocessing.shared_memory" --- Shared memory for direct
    access across processes

  * The "concurrent" package

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

  * "subprocess" --- Subprocess management

  * "sched" --- Event scheduler

  * "queue" --- 同步佇列 (queue) class（類別）

  * "contextvars" --- Context Variables

  * "_thread" --- Low-level threading API

* Networking and Interprocess Communication

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

  * "socket" --- Low-level networking interface

  * "ssl" --- TLS/SSL wrapper for socket objects

  * "select" --- Waiting for I/O completion

  * "selectors" --- High-level I/O multiplexing

  * "signal" --- Set handlers for asynchronous events

  * "mmap" --- Memory-mapped file support

* 網際網路資料處理

  * "email" --- An email and MIME handling package

  * "json" --- JSON encoder and decoder

  * "mailbox" --- Manipulate mailboxes in various formats

  * "mimetypes" --- Map filenames to MIME types

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

  * "binascii" --- Convert between binary and ASCII

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

* Structured Markup Processing Tools

  * "html" --- HyperText Markup Language support

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

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

  * XML 處理模組

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

  * "xml.dom" --- The Document Object Model API

  * "xml.dom.minidom" --- Minimal DOM implementation

  * "xml.dom.pulldom" --- Support for building partial DOM trees

  * "xml.sax" --- Support for SAX2 parsers

  * "xml.sax.handler" --- Base classes for SAX handlers

  * "xml.sax.saxutils" --- SAX Utilities

  * "xml.sax.xmlreader" --- Interface for XML parsers

  * "xml.parsers.expat" --- Fast XML parsing using Expat

* Internet Protocols and Support

  * "webbrowser" --- Convenient web-browser controller

  * "wsgiref" --- WSGI Utilities and Reference Implementation

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

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

  * "urllib.response" --- Response classes used by urllib

  * "urllib.parse" --- Parse URLs into components

  * "urllib.error" --- urllib.request 引發的例外類別

  * "urllib.robotparser" --- robots.txt 的剖析器

  * "http" --- HTTP 模組

  * "http.client" --- HTTP protocol client

  * "ftplib" --- FTP 協定用戶端

  * "poplib" --- POP3 protocol client

  * "imaplib" --- IMAP4 protocol client

  * "smtplib" --- SMTP protocol client

  * "uuid" --- UUID objects according to **RFC 4122**

  * "socketserver" --- A framework for network servers

  * "http.server" --- HTTP servers

  * "http.cookies" --- HTTP state management

  * "http.cookiejar" --- Cookie handling for HTTP clients

  * "xmlrpc" --- XMLRPC server and client modules

  * "xmlrpc.client" --- XML-RPC client access

  * "xmlrpc.server" --- Basic XML-RPC servers

  * "ipaddress" --- IPv4/IPv6 manipulation library

* 多媒體服務

  * "wave" --- Read and write WAV files

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

* 國際化

  * "gettext" --- Multilingual internationalization services

  * "locale" --- Internationalization services

* 程式框架

  * "turtle" --- 龜圖學

  * "cmd" --- Support for line-oriented command interpreters

  * "shlex" --- Simple lexical analysis

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

  * "tkinter" --- Python interface to Tcl/Tk

  * "tkinter.colorchooser" --- Color choosing dialog

  * "tkinter.font" --- Tkinter font wrapper

  * Tkinter Dialogs

  * "tkinter.messagebox" --- Tkinter message prompts

  * "tkinter.scrolledtext" --- Scrolled Text Widget

  * "tkinter.dnd" --- Drag and drop support

  * "tkinter.ttk" --- Tk themed widgets

  * "tkinter.tix" --- Tk 擴充小工具

  * IDLE

* 開發工具

  * "typing" --- Support for type hints

  * "pydoc" --- Documentation generator and online help system

  * Python Development Mode

  * "doctest" --- Test interactive Python examples

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

  * "unittest.mock" --- mock object library

  * "unittest.mock" --- getting started

  * 2to3 --- 自動將 Python 2的程式碼轉成 Python 3

  * "test" --- Regression tests package for Python

  * "test.support" --- Utilities for the Python test suite

  * "test.support.socket_helper" --- Utilities for socket tests

  * "test.support.script_helper" --- Utilities for the Python
    execution tests

  * "test.support.bytecode_helper" --- Support tools for testing
    correct bytecode generation

  * "test.support.threading_helper" --- Utilities for threading tests

  * "test.support.os_helper" --- Utilities for os tests

  * "test.support.import_helper" --- Utilities for import tests

  * "test.support.warnings_helper" --- Utilities for warnings tests

* 除錯與效能分析

  * 稽核事件表

  * "bdb" --- Debugger framework

  * "faulthandler" --- Dump the Python traceback

  * "pdb" --- The Python Debugger

  * The Python Profilers

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

  * "trace" --- Trace or track Python statement execution

  * "tracemalloc" --- Trace memory allocations

* 軟體封裝與發布

  * "distutils" --- Building and installing Python modules

  * "ensurepip" --- Bootstrapping the "pip" installer

  * "venv" --- Creation of virtual environments

  * "zipapp" --- Manage executable Python zip archives

* Python Runtime Services

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

  * "sysconfig" --- Provide access to Python's configuration
    information

  * "builtins" --- 內建物件

  * "__main__" --- Top-level code environment

  * "warnings" --- Warning control

  * "dataclasses" --- Data Classes

  * "contextlib" --- Utilities for "with"-statement contexts

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

  * "atexit" --- Exit handlers

  * "traceback" --- Print or retrieve a stack traceback

  * "__future__" --- Future statement definitions

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

  * "inspect" --- Inspect live objects

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

* Custom Python Interpreters

  * "code" --- Interpreter base classes

  * "codeop" --- Compile Python code

* 引入模組

  * "zipimport" --- Import modules from Zip archives

  * "pkgutil" --- Package extension utility

  * "modulefinder" --- Find modules used by a script

  * "runpy" --- Locating and executing Python modules

  * "importlib" --- The implementation of "import"

  * "importlib.resources" -- Package resource reading, opening and
    access

  * "importlib.resources.abc" -- Abstract base classes for resources

  * "importlib.metadata" -- Accessing package metadata

  * The initialization of the "sys.path" module search path

* Python Language Services

  * "ast" --- Abstract Syntax Trees

  * "symtable" --- Access to the compiler's symbol tables

  * "token" --- Constants used with Python parse trees

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

  * "tokenize" --- Tokenizer for Python source

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

  * "pyclbr" --- Python module browser support

  * "py_compile" --- Compile Python source files

  * "compileall" --- Byte-compile Python libraries

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

  * "pickletools" --- Tools for pickle developers

* MS Windows 特有服務

  * "msvcrt" --- Useful routines from the MS VC++ runtime

  * "winreg" --- Windows registry access

  * "winsound" --- Sound-playing interface for Windows

* Unix 特有服務

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

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

  * "grp" --- The group database

  * "termios" --- POSIX style tty control

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

  * "pty" --- Pseudo-terminal utilities

  * "fcntl" --- The "fcntl" and "ioctl" system calls

  * "resource" --- Resource usage information

  * "syslog" --- Unix syslog library routines

* 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* internals

  * "mailcap" --- Mailcap file handling

  * "msilib" --- 讀寫 Microsoft Installer 檔案

  * "nis" --- Sun NIS (Yellow Pages) 介面

  * "nntplib" --- NNTP 協定客戶端

  * "optparse" --- Parser for command line options

  * "ossaudiodev" --- 對 OSS 相容聲音裝置的存取

  * "pipes" --- shell pipelines 介面

  * "smtpd" --- SMTP 伺服器

  * "sndhdr" --- 判定聲音檔案的型別

  * "spwd" --- shadow 密碼資料庫

  * "sunau" --- 讀寫 Sun AU 檔案

  * "telnetlib" --- Telnet 客戶端

  * "xdrlib" --- uuencode 檔案的編碼與解碼

  * "xdrlib" --- XDR 資料的編碼與解碼

* Security Considerations
