Python 標準函式庫 (Standard Library)¶
The Python Language Reference 說明 Python 這門語言確切的文法及語意,而這份函式庫參考手冊則是說明隨著 Python 一起發佈的標準函式庫,除此之外,其內容也包含一些時常出現在 Python 發佈版本中的非必要套件。
Python 的標準函式庫是非常龐大的,其提供了如下所述極多且涵蓋用途極廣的許多模組。包含一些用 C 語言撰寫,可以操作像是檔案讀寫等系統相關功能的內建模組,當然也有用 Python 撰寫,並使用標準解法解決許多常見問題的模組。其中有些模組則是特別針對 Python 的可攜性去設計的,為此特地將一些平台特殊相依性的功能抽象化成可跨平台的 API。
Python 的 Windows 安裝檔基本上包含整個標準函式庫,且通常也包含許多額外套件;而類 Unix 作業系統方面,Python 則提供一系列的套件,對於某些非必要性的套件,可能得使用該作業系統提供的套件管理工具來安裝。
In addition to the standard library, there is a growing collection of several thousand components (from individual programs and modules to packages and entire application development frameworks), available from the Python Package Index.
- 1. 簡介
- 2. 內建函式
- 3. 內建常數
- 4. 內建型態
- 4.1. Truth Value Testing
- 4.2. Boolean Operations —
and,or,not - 4.3. Comparisons
- 4.4. Numeric Types —
int,float,complex - 4.5. Iterator Types
- 4.6. Sequence Types —
list,tuple,range - 4.7. Text Sequence Type —
str - 4.8. Binary Sequence Types —
bytes,bytearray,memoryview - 4.9. Set Types —
set,frozenset - 4.10. Mapping Types —
dict - 4.11. Context Manager Types
- 4.12. Other Built-in Types
- 4.13. Special Attributes
- 5. 內建的例外
- 6. Text Processing Services
- 6.1.
string— Common string operations - 6.2.
re— Regular expression operations - 6.3.
difflib— Helpers for computing deltas - 6.4.
textwrap— Text wrapping and filling - 6.5.
unicodedata— Unicode Database - 6.6.
stringprep— Internet String Preparation - 6.7.
readline— GNU readline interface - 6.8.
rlcompleter— Completion function for GNU readline
- 6.1.
- 7. Binary Data Services
- 8. Data Types
- 8.1.
datetime— Basic date and time types - 8.2.
calendar— General calendar-related functions - 8.3.
collections— 容器資料型態 - 8.4.
collections.abc— Abstract Base Classes for Containers - 8.5.
heapq— 堆積佇列 (heap queue) 演算法 - 8.6.
bisect— 陣列二分演算法 (Array bisection algorithm) - 8.7.
array— 高效率的數值型態陣列 - 8.8.
weakref— Weak references - 8.9.
types— Dynamic type creation and names for built-in types - 8.10.
copy— Shallow and deep copy operations - 8.11.
pprint— Data pretty printer - 8.12.
reprlib— Alternaterepr()implementation - 8.13.
enum— Support for enumerations
- 8.1.
- 9. 數值與數學模組
- 9.1.
numbers— Numeric abstract base classes - 9.2.
math— Mathematical functions - 9.3.
cmath— Mathematical functions for complex numbers - 9.4.
decimal— Decimal fixed point and floating point arithmetic - 9.5.
fractions— Rational numbers - 9.6.
random— Generate pseudo-random numbers - 9.7.
statistics— 數學統計函式
- 9.1.
- 10. 函式編程模組
- 11. 檔案與目錄存取
- 11.1.
pathlib— Object-oriented filesystem paths - 11.2.
os.path— Common pathname manipulations - 11.3.
fileinput— Iterate over lines from multiple input streams - 11.4.
stat— Interpretingstat()results - 11.5.
filecmp— File and Directory Comparisons - 11.6.
tempfile— Generate temporary files and directories - 11.7.
glob— Unix style pathname pattern expansion - 11.8.
fnmatch— Unix filename pattern matching - 11.9.
linecache— Random access to text lines - 11.10.
shutil— High-level file operations - 11.11.
macpath— Mac OS 9 path manipulation functions
- 11.1.
- 12. Data Persistence
- 13. 資料壓縮與保存
- 14. 檔案格式
- 15. Cryptographic Services
- 16. Generic Operating System Services
- 16.1.
os— Miscellaneous operating system interfaces - 16.2.
io— Core tools for working with streams - 16.3.
time— Time access and conversions - 16.4.
argparse— Parser for command-line options, arguments and sub-commands - 16.5.
getopt— C-style parser for command line options - 16.6.
logging— Logging facility for Python - 16.7.
logging.config— Logging configuration - 16.8.
logging.handlers— Logging handlers - 16.9.
getpass— Portable password input - 16.10.
curses— Terminal handling for character-cell displays - 16.11.
curses.textpad— Text input widget for curses programs - 16.12.
curses.ascii— Utilities for ASCII characters - 16.13.
curses.panel— A panel stack extension for curses - 16.14.
platform— Access to underlying platform’s identifying data - 16.15.
errno— Standard errno system symbols - 16.16.
ctypes— A foreign function library for Python
- 16.1.
- 17. Concurrent Execution
- 17.1.
threading— Thread-based parallelism - 17.2.
multiprocessing— Process-based parallelism - 17.3. The
concurrentpackage - 17.4.
concurrent.futures— Launching parallel tasks - 17.5.
subprocess— Subprocess management - 17.6.
sched— Event scheduler - 17.7.
queue— A synchronized queue class - 17.8.
_thread— Low-level threading API - 17.9.
_dummy_thread— Drop-in replacement for the_threadmodule - 17.10.
dummy_threading— Drop-in replacement for thethreadingmodule
- 17.1.
- 18.
contextvars— Context Variables - 19. Interprocess Communication and Networking
- 19.1.
socket— Low-level networking interface - 19.2.
ssl— TLS/SSL wrapper for socket objects - 19.3.
select— Waiting for I/O completion - 19.4.
selectors— High-level I/O multiplexing - 19.5.
asyncio— Asynchronous I/O, event loop, coroutines and tasks - 19.6.
asyncore— Asynchronous socket handler - 19.7.
asynchat— Asynchronous socket command/response handler - 19.8.
signal— Set handlers for asynchronous events - 19.9.
mmap— Memory-mapped file support
- 19.1.
- 20. Internet Data Handling
- 20.1.
email— An email and MIME handling package - 20.2.
json— JSON encoder and decoder - 20.3.
mailcap— Mailcap file handling - 20.4.
mailbox— Manipulate mailboxes in various formats - 20.5.
mimetypes— Map filenames to MIME types - 20.6.
base64—— Base16、Base32、Base64、Base85 資料編碼 - 20.7.
binhex— Encode and decode binhex4 files - 20.8.
binascii— Convert between binary and ASCII - 20.9.
quopri— Encode and decode MIME quoted-printable data - 20.10.
uu— Encode and decode uuencode files
- 20.1.
- 21. Structured Markup Processing Tools
- 21.1.
html— HyperText Markup Language support - 21.2.
html.parser— Simple HTML and XHTML parser - 21.3.
html.entities— Definitions of HTML general entities - 21.4. XML 處理模組
- 21.5.
xml.etree.ElementTree— The ElementTree XML API - 21.6.
xml.dom— The Document Object Model API - 21.7.
xml.dom.minidom— Minimal DOM implementation - 21.8.
xml.dom.pulldom— Support for building partial DOM trees - 21.9.
xml.sax— Support for SAX2 parsers - 21.10.
xml.sax.handler— Base classes for SAX handlers - 21.11.
xml.sax.saxutils— SAX Utilities - 21.12.
xml.sax.xmlreader— Interface for XML parsers - 21.13.
xml.parsers.expat— Fast XML parsing using Expat
- 21.1.
- 22. Internet Protocols and Support
- 22.1.
webbrowser— Convenient Web-browser controller - 22.2.
cgi— Common Gateway Interface support - 22.3.
cgitb— Traceback manager for CGI scripts - 22.4.
wsgiref— WSGI Utilities and Reference Implementation - 22.5.
urllib— URL handling modules - 22.6.
urllib.request— Extensible library for opening URLs - 22.7.
urllib.response— Response classes used by urllib - 22.8.
urllib.parse— Parse URLs into components - 22.9.
urllib.error— Exception classes raised by urllib.request - 22.10.
urllib.robotparser— Parser for robots.txt - 22.11.
http— HTTP modules - 22.12.
http.client— HTTP protocol client - 22.13.
ftplib— FTP protocol client - 22.14.
poplib— POP3 protocol client - 22.15.
imaplib— IMAP4 protocol client - 22.16.
nntplib— NNTP protocol client - 22.17.
smtplib— SMTP protocol client - 22.18.
smtpd— SMTP Server - 22.19.
telnetlib— Telnet client - 22.20.
uuid— UUID objects according to RFC 4122 - 22.21.
socketserver— A framework for network servers - 22.22.
http.server— HTTP servers - 22.23.
http.cookies— HTTP state management - 22.24.
http.cookiejar— Cookie handling for HTTP clients - 22.25.
xmlrpc— XMLRPC server and client modules - 22.26.
xmlrpc.client— XML-RPC client access - 22.27.
xmlrpc.server— Basic XML-RPC servers - 22.28.
ipaddress— IPv4/IPv6 manipulation library
- 22.1.
- 23. Multimedia Services
- 23.1.
audioop— Manipulate raw audio data - 23.2.
aifc— Read and write AIFF and AIFC files - 23.3.
sunau— Read and write Sun AU files - 23.4.
wave— Read and write WAV files - 23.5.
chunk— Read IFF chunked data - 23.6.
colorsys— Conversions between color systems - 23.7.
imghdr— Determine the type of an image - 23.8.
sndhdr— Determine type of sound file - 23.9.
ossaudiodev— Access to OSS-compatible audio devices
- 23.1.
- 24. 國際化
- 25. 程式框架
- 26. 以 Tk 打造 GUI
- 27. 開發工具
- 27.1.
typing— Support for type hints - 27.2.
pydoc— Documentation generator and online help system - 27.3.
doctest— Test interactive Python examples - 27.4.
unittest— 單元測試框架 - 27.5.
unittest.mock— mock object library - 27.6.
unittest.mock— getting started - 27.7. 2to3 - 自動將 Python 2的程式碼轉成 Python 3
- 27.8.
test— Regression tests package for Python - 27.9.
test.support— Utilities for the Python test suite - 27.10.
test.support.script_helper— Utilities for the Python execution tests
- 27.1.
- 28. Debugging and Profiling
- 29. 軟體封裝與發布
- 30. Python Runtime Services
- 30.1.
sys— System-specific parameters and functions - 30.2.
sysconfig— Provide access to Python’s configuration information - 30.3.
builtins— Built-in objects - 30.4.
__main__— Top-level script environment - 30.5.
warnings— Warning control - 30.6.
dataclasses— Data Classes - 30.7.
contextlib— Utilities forwith-statement contexts - 30.8.
abc— Abstract Base Classes - 30.9.
atexit— Exit handlers - 30.10.
traceback— Print or retrieve a stack traceback - 30.11.
__future__— Future statement definitions - 30.12.
gc— Garbage Collector interface - 30.13.
inspect— Inspect live objects - 30.14.
site— Site-specific configuration hook
- 30.1.
- 31. Custom Python Interpreters
- 32. 匯入模組
- 33. Python Language Services
- 33.1.
parser— Access Python parse trees - 33.2.
ast— Abstract Syntax Trees - 33.3.
symtable— Access to the compiler’s symbol tables - 33.4.
symbol— Constants used with Python parse trees - 33.5.
token— Constants used with Python parse trees - 33.6.
keyword— Testing for Python keywords - 33.7.
tokenize— Tokenizer for Python source - 33.8.
tabnanny— Detection of ambiguous indentation - 33.9.
pyclbr— Python class browser support - 33.10.
py_compile— Compile Python source files - 33.11.
compileall— Byte-compile Python libraries - 33.12.
dis— Python bytecode的反組譯器 - 33.13.
pickletools— Tools for pickle developers
- 33.1.
- 34. Miscellaneous Services
- 35. MS Windows Specific Services
- 36. Unix Specific Services
- 36.1.
posix— The most common POSIX system calls - 36.2.
pwd— The password database - 36.3.
spwd— The shadow password database - 36.4.
grp— The group database - 36.5.
crypt— Function to check Unix passwords - 36.6.
termios— POSIX style tty control - 36.7.
tty— Terminal control functions - 36.8.
pty— Pseudo-terminal utilities - 36.9.
fcntl— Thefcntlandioctlsystem calls - 36.10.
pipes— Interface to shell pipelines - 36.11.
resource— Resource usage information - 36.12.
nis— Interface to Sun’s NIS (Yellow Pages) - 36.13.
syslog— Unix syslog library routines
- 36.1.
- 37. Superseded Modules
- 38. Undocumented Modules
