Python 標準ライブラリ¶
Python 言語リファレンス ではプログラミング言語 Python の厳密な構文とセマンティクスについて説明されていますが、このライブラリリファレンスマニュアルでは Python とともに配付されている標準ライブラリについて説明します。また Python 配布物に収められていることの多いオプションのコンポーネントについても説明します。
Python の標準ライブラリはとても拡張性があり、下の長い目次のリストで判るように幅広いものを用意しています。このライブラリには、例えばファイル I/O のように、Python プログラマが直接アクセスできないシステム機能へのアクセス機能を提供する (Cで書かれた) 組み込みモジュールや、日々のプログラミングで生じる多くの問題に標準的な解決策を提供するPython で書かれたモジュールが入っています。これら数多くのモジュールには、プラットフォーム固有の事情をプラットフォーム独立な API へと昇華させることにより、Pythonプログラムに移植性を持たせ、それを高めるという明確な意図があります。
Windows 向けの Python インストーラはたいてい標準ライブラリのすべてを含み、しばしばそれ以外の追加のコンポーネントも含んでいます。Unix 系のオペレーティングシステムの場合は Python は一揃いのパッケージとして提供されるのが普通で、オプションのコンポーネントを手に入れるにはオペレーティングシステムのパッケージツールを使うことになるでしょう。
標準ライブラリに加えて、数10万のコンポーネントが (独立したプログラムやモジュールからパッケージ、アプリケーション開発フレームワークまで) 活動しているコレクションとしてPython Package Index から入手可能です。
- はじめに
- 組み込み関数
- 組み込み定数
- 組み込み型
- 組み込み例外
- テキスト処理サービス
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
- バイナリデータ処理
- データ型
datetime--- Basic date and time typeszoneinfo--- IANA time zone supportcalendar--- General calendar-related functionscollections--- Container datatypescollections.abc--- Abstract Base Classes for Containersheapq--- Heap queue algorithmbisect--- Array bisection algorithmarray--- Efficient arrays of numeric valuesweakref--- 弱参照types--- Dynamic type creation and names for built-in typescopy--- Shallow and deep copy operationspprint--- Data pretty printerreprlib--- Alternaterepr()implementationenum--- Support for enumerationsgraphlib--- Functionality to operate with graph-like structures
- 数値と数学モジュール
numbers--- Numeric abstract base classesmath--- Mathematical functionscmath--- Mathematical functions for complex numbersdecimal--- Decimal fixed point and floating point arithmeticfractions--- Rational numbersrandom--- Generate pseudo-random numbersstatistics--- Mathematical statistics functions
- 関数型プログラミング用モジュール
- ファイルとディレクトリへのアクセス
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 operations
- データの永続化
- データ圧縮とアーカイブ
- ファイルフォーマット
- 暗号関連のサービス
- 汎用オペレーティングシステムサービス
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--- curses プログラムのためのテキスト入力ウィジェットcurses.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
- 並行実行
threading--- Thread-based parallelismmultiprocessing--- Process-based parallelismmultiprocessing.shared_memory--- Shared memory for direct access across processesconcurrentパッケージconcurrent.futures--- Launching parallel taskssubprocess--- Subprocess managementsched--- Event schedulerqueue--- A synchronized queue classcontextvars--- Context Variables_thread--- Low-level threading API
- ネットワーク通信とプロセス間通信
- インターネット上のデータの操作
email--- An email and MIME handling packagejson--- JSON encoder and decodermailbox--- Manipulate mailboxes in various formatsmimetypes--- Map filenames to MIME typesbase64--- Base16, Base32, Base64, Base85 Data Encodingsbinascii--- Convert between binary and ASCIIquopri--- Encode and decode MIME quoted-printable data
- 構造化マークアップツール
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
- インターネットプロトコルとサポート
webbrowser--- Convenient web-browser controllerwsgiref--- WSGI Utilities and Reference Implementationurllib--- URL handling modulesurllib.request--- Extensible library for opening URLsurllib.response--- urllib で使用するレスポンスクラスurllib.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 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 サーバーとクライアントモジュール群xmlrpc.client--- XML-RPC client accessxmlrpc.server--- Basic XML-RPC serversipaddress--- IPv4/IPv6 manipulation library
- マルチメディアサービス
- 国際化
- プログラムのフレームワーク
- Tk を用いたグラフィカルユーザーインターフェース
tkinter--- Python interface to Tcl/Tktkinter.colorchooser--- Color choosing dialogtkinter.font--- Tkinter font wrapper- Tkinter ダイアログ
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 開発モード
doctest--- Test interactive Python examplesunittest--- Unit testing frameworkunittest.mock--- mock object libraryunittest.mock--- getting started- 2to3 --- Python 2 から 3 への自動コード変換
test--- Regression tests package for Pythontest.support--- テストのためのユーティリティ関数test.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 ランタイムサービス
sys--- System-specific parameters and functionssysconfig--- Provide access to Python's configuration informationbuiltins--- Built-in objects__main__--- Top-level code environmentwarnings--- Warning controldataclasses--- データクラスcontextlib---with文コンテキスト用ユーティリティabc--- 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
- カスタム Python インタプリタ
- モジュールのインポート
zipimport--- Import modules from Zip archivespkgutil--- Package extension utilitymodulefinder--- Find modules used by a scriptrunpy--- Locating and executing Python modulesimportlib---importの実装importlib.resources-- Package resource reading, opening and accessimportlib.resources.abc-- Abstract base classes for resourcesimportlib.metadata-- パッケージメタデータへのアクセスsys.pathモジュール検索パスの初期化
- Python言語サービス
ast--- Abstract Syntax Treessymtable--- Access to the compiler's symbol tablestoken--- 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--- Disassembler for Python bytecodepickletools--- Tools for pickle developers
- MS Windows 固有のサービス
- Unix 固有のサービス
posix--- The most common POSIX system callspwd--- The password databasegrp--- The group databasetermios--- POSIX style tty controltty--- Terminal control functionspty--- Pseudo-terminal utilitiesfcntl--- Thefcntlandioctlsystem callsresource--- Resource usage informationsyslog--- Unix syslog library routines
- モジュールのコマンドラインインターフェース (CLI)
- 取って代わられたモジュール群
aifc--- Read and write AIFF and AIFC filesasynchat--- Asynchronous socket command/response handlerasyncore--- Asynchronous socket handleraudioop--- Manipulate raw audio datacgi--- Common Gateway Interface supportcgitb--- Traceback manager for CGI scriptschunk--- Read IFF chunked datacrypt--- Function to check Unix passwordsimghdr--- Determine the type of an imageimp--- Access the import internalsmailcap--- Mailcap file handlingmsilib--- Read and write Microsoft Installer filesnis--- Interface to Sun's NIS (Yellow Pages)nntplib--- NNTP protocol clientoptparse--- Parser for command line optionsossaudiodev--- Access to OSS-compatible audio devicespipes--- Interface to shell pipelinessmtpd--- SMTP Serversndhdr--- Determine type of sound filespwd--- The shadow password databasesunau--- Read and write Sun AU filestelnetlib--- Telnet clientuu--- Encode and decode uuencode filesxdrlib--- Encode and decode XDR data
- セキュリティで考慮すべき点