Python 標准庫¶
Python 語言參考 描述了 Python 語言的具體語法和語義,這份庫參考則介紹了與 Python 一同發行的標准庫。它還描述了通常包含在 Python 發行版中的一些可選組件。
Python 標准庫非常龐大,所提供的組件涉及范圍十分廣泛,正如以下內容目錄所顯示的。這個庫包含了多個內置模塊 (以 C 編寫),Python 程序員必須依靠它們來實現系統級功能,例如文件 I/O,此外還有大量以 Python 編寫的模塊,提供了日常編程中許多問題的標准解決方案。其中有些模塊經過專門設計,通過將特定平台功能抽象化為平台中立的 API 來鼓勵和加強 Python 程序的可移植性。
Windows 版本的 Python 安裝程序通常包含整個標准庫,往往還包含許多額外組件。對於類 Unix 操作系統,Python 通常會分成一系列的軟件包,因此可能需要使用操作系統所提供的包管理工具來獲取部分或全部可選組件。
在這個標准庫以外還存在成千上萬並且不斷增加的其他組件 (從單獨的程序、模塊、軟件包直到完整的應用開發框架),訪問 Python 包索引 即可獲取這些第三方包。
- 概述
- 內置函數
- 內置常量
- 內置類型
- 內置異常
- 文本處理服務
- 二進制數據服務
- 數據類型
datetime
--- 基礎 日期 和 時間 數據類型calendar
--- 日歷相關函數collections
--- 容器數據類型collections.abc
--- 容器的抽象基類heapq
--- 堆隊列算法bisect
--- Array bisection algorithmarray
--- Efficient arrays of numeric valuesweakref
--- 弱引用types
--- Dynamic type creation and names for built-in typescopy
--- 淺層 (shallow) 和深層 (deep) 復制操作pprint
--- 數據美化輸出reprlib
--- Alternaterepr()
implementationenum
--- Support for enumerations
- 數字和數學模塊
- 函數式編程模塊
- 文件和目錄訪問
pathlib
--- 面向對象的文件系統路徑os.path
--- 常見路徑操作fileinput
--- Iterate over lines from multiple input streamsstat
--- Interpretingstat()
resultsfilecmp
--- File and Directory Comparisonstempfile
--- Generate temporary files and directoriesglob
--- Unix style pathname pattern expansionfnmatch
--- Unix filename pattern matchinglinecache
--- Random access to text linesshutil
--- High-level file operationsmacpath
--- Mac OS 9 路徑操作函數
- 數據持久化
- 數據壓縮和存檔
- 文件格式
- 加密服務
- 通用操作系統服務
os
--- 操作系統接口模塊io
--- 處理流的核心工具time
--- 時間的訪問和轉換argparse
--- 命令行選項、參數和子命令解析器getopt
--- C-style parser for command line options- 模塊
logging
--- Python 的日志記錄工具 logging.config
--- 日志記錄配置logging.handlers
--- Logging handlersgetpass
--- 便攜式密碼輸入工具curses
--- 終端字符單元顯示的處理curses.textpad
--- Text input widget for curses programscurses.ascii
--- Utilities for ASCII characterscurses.panel
--- A panel stack extension for cursesplatform
--- 獲取底層平台的標識數據errno
--- Standard errno system symbolsctypes
--- Python 的外部函數庫
- 並發執行
contextvars
--- Context Variables- 網絡和進程間通信
- 互聯網數據處理
email
--- 電子郵件與 MIME 處理包json
--- JSON 編碼和解碼器mailcap
--- Mailcap file handlingmailbox
--- Manipulate mailboxes in various formatsmimetypes
--- Map filenames to MIME typesbase64
--- Base16, Base32, Base64, Base85 數據編碼binhex
--- 對binhex4文件進行編碼和解碼binascii
--- 二進制和 ASCII 碼互轉quopri
--- Encode and decode MIME quoted-printable datauu
--- Encode and decode uuencode files
- 結構化標記處理工具
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
- 互聯網協議和支持
webbrowser
--- 方便的Web瀏覽器控制器cgi
--- Common Gateway Interface supportcgitb
--- Traceback manager for CGI scriptswsgiref
--- WSGI Utilities and Reference Implementationurllib
--- URL 處理模塊urllib.request
--- 用於打開 URL 的可擴展庫urllib.response
--- Response classes used by urlliburllib.parse
--- Parse URLs into componentsurllib.error
--- Exception classes raised by urllib.requesturllib.robotparser
--- Parser for robots.txthttp
--- HTTP 模塊- http.client --- HTTP協議客戶端
ftplib
--- FTP protocol clientpoplib
--- POP3 protocol clientimaplib
--- IMAP4 protocol clientnntplib
--- NNTP protocol clientsmtplib
---SMTP協議客戶端smtpd
--- SMTP Servertelnetlib
--- Telnet clientuuid
--- UUID objects according to RFC 4122socketserver
--- A framework for network servershttp.server
--- HTTP 服務器http.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圖形用戶界面(GUI)
- 開發工具
typing
--- 類型標注支持pydoc
--- Documentation generator and online help systemdoctest
--- 測試交互性的Python示例unittest
--- 單元測試框架unittest.mock
--- mock object libraryunittest.mock
上手指南- 2to3 - 自動將 Python 2 代碼轉為 Python 3 代碼
test
--- Regression tests package for Pythontest.support
--- Utilities for the Python test suitetest.support.script_helper
--- Utilities for the Python execution tests
- 調試和分析
- 軟件打包和分發
- Python運行時服務
sys
--- 系統相關的參數和函數sysconfig
--- Provide access to Python's configuration informationbuiltins
--- 內建對象__main__
--- 頂層腳本環境warnings
--- Warning controldataclasses
--- 數據類contextlib
--- Utilities forwith
-statement contextsabc
--- 抽象基類atexit
--- 退出處理器traceback
--- 打印或檢索堆棧回溯__future__
--- Future 語句定義gc
--- 垃圾回收器接口inspect
--- 檢查對象site
--- Site-specific configuration hook
- 自定義 Python 解釋器
- 導入模塊
- Python 語言服務
parser
--- Access Python parse treesast
--- 抽象語法樹symtable
--- Access to the compiler's symbol tablessymbol
--- 與 Python 解析樹一起使用的常量token
--- 與Python解析樹一起使用的常量keyword
--- 檢驗Python關鍵字tokenize
--- Tokenizer for Python sourcetabnanny
--- 模糊縮進檢測pyclbr
--- Python class browser supportpy_compile
--- Compile Python source filescompileall
--- Byte-compile Python librariesdis
--- Python 字節碼反匯編器pickletools
--- Tools for pickle developers
- 雜項服務
- Windows系統相關模塊
- Unix 專有服務
posix
--- The most common POSIX system callspwd
--- 用戶密碼數據庫spwd
--- The shadow password databasegrp
--- The group databasecrypt
--- Function to check Unix passwordstermios
--- POSIX style tty controltty
--- 終端控制功能pty
--- Pseudo-terminal utilitiesfcntl
--- Thefcntl
andioctl
system callspipes
--- Interface to shell pipelinesresource
--- Resource usage informationnis
--- Interface to Sun's NIS (Yellow Pages)- Unix syslog 庫例程
- 被取代的模塊
- 未創建文檔的模塊