On this page
pydoc
Prev: pyclbr | Up: stdlib_module | Next: pydoc_data
Rel: typing, annotationlib, pydoc_data, doctest, unittest
Ref: docs.python.org — pydoc
Tags: #public #python3 #stdlib
Import
import pydoc
Overview
Python's built-in documentation generator (python3 -m pydoc, pydoc.render_doc(), pydoc.doc(), and the interactive help() system). Use pydoc from the CLI to browse installed package docs offline or start a local documentation browser (python3 -m pydoc -b), or programmatically to render plain-text/HTML docstrings.
Quick Start
import pydoc
plain = pydoc.render_doc("math", renderer=pydoc.plaintext)
assert "FUNCTIONS" in plain and "sqrt(" in plain
Implementation Walkthrough
1. Generating Offline HTML or CLI Reference Docs
Common CLI workflows:
python3 -m pydoc json— page through module docs in your terminal.python3 -m pydoc -k compress— keyword search across all installed modules.python3 -m pydoc -w mypkg— writemypkg.htmlinto the current directory.python3 -m pydoc -b— launch a local web browser server for all installed packages.
Gotchas & Boundaries
pydocimports the target module: Inspecting a module executes its top-level code; don't pointpydocat untrusted scripts or modules with side effects at import time.- Basic styling: For publishable project documentation with Markdown/reST guides and cross-references, use Sphinx, MkDocs, or
pdoc.
Common Functions
- pydoc.help() —
help(request=<object object at 0x1040b5880>)—pydoc.help()function.
Examples & Notes
Generate and view documentation from docstrings (python3 -m pydoc <name>):
def calculate_total(amounts):
"""
:param amounts: The list of amounts
:return: The grand total
"""
return sum(amounts)
Linked from
- tuts/python3
- tuts/python3/stdlib_module
- tuts/python3/stdlib_module/annotationlib
- tuts/python3/stdlib_module/bdb
- tuts/python3/stdlib_module/cProfile
- tuts/python3/stdlib_module/doctest
- tuts/python3/stdlib_module/faulthandler
- tuts/python3/stdlib_module/pdb
- tuts/python3/stdlib_module/profile
- tuts/python3/stdlib_module/pstats
- tuts/python3/stdlib_module/pyclbr
- tuts/python3/stdlib_module/pydoc/help
- tuts/python3/stdlib_module/pydoc_data
- tuts/python3/stdlib_module/stdlib_module
- tuts/python3/stdlib_module/timeit
- tuts/python3/stdlib_module/trace
- tuts/python3/stdlib_module/tracemalloc
- tuts/python3/stdlib_module/typing
- tuts/python3/stdlib_module/unittest
Related notes
- tuts/python3/stdlib_module/annotationlib Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/doctest Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/pyclbr Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/pydoc/help Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/pydoc_data Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/stdlib_module Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/typing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/unittest Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/bdb links to this page; shared tags: #stdlib