Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to view Python documentation using pydoc

📅 2019-Dec-29 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ python ⬩ 📚 Archive

Python ships with a documentation generating and viewing tool called pydoc. This tool can be used to lookup and peruse documentation for everything in the Python standard library and also for your own modules and scripts. The tool can render documentation like a manpage or dump it to a simple HTML file or serve it from a local HTTP server.

$ readlink -m `which pydoc3`
$ readlink -m `which pydoc`
$ pydoc os
$ pydoc os.path
$ pydoc os.path.join

This renders the docstring of the module or method colorfully formatted like a manpage. This is great for quick lookups at the shell in the midst of programming. This can be a great alternative to Googling or visiting the official Python guide online.

$ pydoc foobar

Note how the tool requires the module name, so we drop the .py file extension.

$ pydoc -p 9999

This serves up the Python documentation as HTML pages at the http://localhost:9999 URL. Once you open this URL in your local browser you can find the Python standard documentation rendered as simple formatted HTML webpages. Navigating to specific modules is not clear here. For example, I could not find os.path documentation listed at http://localhost:9999, but it was available when I specifically typed http://localhost:9999/os.path.html into the addressbar.

$ pydoc -w os.path
$ pydoc -g

This threw up a Tkinter GUI tool, but it did not render the documentation.

Tried with: Ubuntu 18.04