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.
- 簡介
- 內建函式
- 內建常數
- 內建型態
- Truth Value Testing
- 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
- Other Built-in Types
- Special Attributes
- Integer string conversion length limitation
- 內建的例外
- Text Processing Services
string--- Common string operationsre--- Regular expression operationsdifflib--- Helpers for computing deltastextwrap--- Text wrapping and fillingunicodedata--- Unicode Databasestringprep--- Internet String Preparationreadline--- GNU readline interfacerlcompleter--- Completion function for GNU readline
- Binary Data Services
- Data Types
datetime--- Basic date and time typescalendar--- 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 and deep copy operationspprint--- Data pretty printerreprlib--- Alternaterepr()implementationenum--- Support for enumerations
- 數值與數學模組
- 函式編程模組
- 檔案與目錄存取
pathlib--- Object-oriented filesystem pathsos.path--- Common pathname manipulationsfileinput--- 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 path manipulation functions
- Data Persistence
- 資料壓縮與保存
- 檔案格式
- Cryptographic Services
- Generic Operating System Services
os--- Miscellaneous operating system interfacesio--- Core tools for working with streamstime--- 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--- Portable password inputcurses--- Terminal handling for character-cell displayscurses.textpad--- Text input widget for curses programscurses.ascii--- Utilities for ASCII characterscurses.panel--- A panel stack extension for cursesplatform--- Access to underlying platform's identifying dataerrno--- Standard errno system symbolsctypes--- A foreign function library for Python
- Concurrent Execution
threading--- Thread-based parallelismmultiprocessing--- Process-based parallelism- The
concurrentpackage concurrent.futures--- Launching parallel taskssubprocess--- Subprocess managementsched--- Event schedulerqueue--- A synchronized queue class_thread--- Low-level threading API_dummy_thread--- Drop-in replacement for the_threadmoduledummy_threading--- Drop-in replacement for thethreadingmodule
contextvars--- Context Variables- Networking and Interprocess Communication
asyncio--- Asynchronous I/Osocket--- Low-level networking interfacessl--- TLS/SSL wrapper for socket objectsselect--- Waiting for I/O completionselectors--- High-level I/O multiplexingasyncore--- Asynchronous socket handlerasynchat--- Asynchronous socket command/response handlersignal--- Set handlers for asynchronous eventsmmap--- Memory-mapped file support
- Internet Data Handling
email--- An email and MIME handling packagejson--- JSON encoder and decodermailcap--- Mailcap file handlingmailbox--- Manipulate mailboxes in various formatsmimetypes--- Map filenames to MIME typesbase64—— Base16、Base32、Base64、Base85 資料編碼binhex--- Encode and decode binhex4 filesbinascii--- Convert between binary and ASCIIquopri--- Encode and decode MIME quoted-printable datauu--- Encode and decode uuencode files
- Structured Markup Processing Tools
html--- HyperText Markup Language supporthtml.parser--- Simple HTML and XHTML parserhtml.entities--- Definitions of HTML general entities- 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 controllercgi--- Common Gateway Interface supportcgitb--- Traceback manager for CGI scriptswsgiref--- WSGI Utilities and Reference Implementationurllib--- URL handling modulesurllib.request--- Extensible library for opening URLsurllib.response--- Response classes used by urlliburllib.parse--- Parse URLs into componentsurllib.error--- Exception classes raised by urllib.requesturllib.robotparser--- Parser for robots.txthttp--- HTTP moduleshttp.client--- HTTP protocol clientftplib--- FTP protocol clientpoplib--- POP3 protocol clientimaplib--- IMAP4 protocol clientnntplib--- NNTP protocol clientsmtplib--- SMTP protocol clientsmtpd--- SMTP Servertelnetlib--- Telnet 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
- Multimedia Services
audioop--- Manipulate raw audio dataaifc--- Read and write AIFF and AIFC filessunau--- Read and write Sun AU fileswave--- Read and write WAV fileschunk--- Read IFF chunked datacolorsys--- Conversions between color systemsimghdr--- Determine the type of an imagesndhdr--- Determine type of sound fileossaudiodev--- Access to OSS-compatible audio devices
- 國際化
- 程式框架
- 以 Tk 打造 GUI
- 開發工具
typing--- Support for type hintspydoc--- Documentation generator and online help systemdoctest--- 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.script_helper--- Utilities for the Python execution tests
- Debugging and Profiling
- 軟體封裝與發布
- Python Runtime Services
sys--- System-specific parameters and functionssysconfig--- Provide access to Python's configuration informationbuiltins--- Built-in objects__main__--- Top-level script environmentwarnings--- Warning controldataclasses--- Data Classescontextlib--- Utilities forwith-statement contextsabc--- Abstract Base Classesatexit--- Exit handlerstraceback--- Print or retrieve a stack traceback__future__--- Future statement definitionsgc--- Garbage Collector interfaceinspect--- Inspect live objectssite--- Site-specific configuration hook
- Custom Python Interpreters
- 匯入模組
- Python Language Services
parser--- Access Python parse treesast--- Abstract Syntax Treessymtable--- Access to the compiler's symbol tablessymbol--- Constants used with Python parse treestoken--- Constants used with Python parse treeskeyword--- Testing for Python keywordstokenize--- Tokenizer for Python sourcetabnanny--- Detection of ambiguous indentationpyclbr--- Python module browser supportpy_compile--- Compile Python source filescompileall--- Byte-compile Python librariesdis--- Python bytecode的反組譯器pickletools--- Tools for pickle developers
- Miscellaneous Services
- MS Windows Specific Services
- Unix Specific Services
posix--- The most common POSIX system callspwd--- The password databasespwd--- The shadow password databasegrp--- The group databasecrypt--- Function to check Unix passwordstermios--- POSIX style tty controltty--- Terminal control functionspty--- Pseudo-terminal utilitiesfcntl--- Thefcntlandioctlsystem callspipes--- Interface to shell pipelinesresource--- Resource usage informationnis--- Interface to Sun's NIS (Yellow Pages)syslog--- Unix syslog library routines
- Superseded Modules
- Undocumented Modules
