Search python docs offline?

Question:

In python I can get some rudimentary documentation for any object using help(<object>). But to be able to search the documentation, I have to go online. This isn’t really helpful if I’m somewhere where the internet isn’t accessible.

In R, there is a handy double question mark feature (??<topic>) that allows me to search through the documentation of all installed libraries for any function that includes <topic> in its name or documentation string. Is there anything similar for python? Perhaps even just for loaded objects?

Asked By: naught101

||

Answers:

You should try ipython.

object_name? will print all sorts of details about any object,
including docstrings, function definition lines (for call arguments)
and constructor details for classes.

The magic commands %pdoc, %pdef, %psource and %pfile will respectively print the docstring, function definition line, full source code and the complete file for any object (when they can be found). If automagic is on (it is by default), you don’t need to type the ‘%’ explicitly.

Answered By: Leonardo.Z

Windows Idle – F1 from shell window or editing window gets you a windows help file of all the docs. I think it’s better than the online version – it’s easier to find stuff.

Answered By: wwii

Although there are certainly better documentations built into your computer than help() like windows idle, another option for some of the more common topics would just be to save some of the online documentation to your computer. For the modules you use a lot and want to access offline, you could just download a text file version of the official online python documentation, which is the best place to get documentation. (file > save page as > select .txt file format)

Answered By: trevorKirkby

In case your working in a Mac there is Dash, which allows you to download docsets and then explore/search offline. Despite its documentation functionality, Dash is also a Snippet Manager.

Answered By: simme

Just to add another option for offline access of python docs (mostly core):

I don’t have access to a linux computer at the moment, but on windows, you can navigate to your_python_dist_folder/doc to find some help files. Particularly python275.chm for instance.

If there’s no doc folder on your linux machine, you can download the file here and google for a linux chm viewer:

https://www.google.com/search?q=linux+chm+viewer

::Note:

Some distributions also include docs for other packages in there… might be worth a check. Other than that, help(module) usually returns good information.

Edit:

You could get something that might be a little closer to what you want by using pydoc. E.g. you are looking for something about sin in the math module:

import math
import pydoc
[i for i in dir(math) if 'sin' in pydoc.getdoc(getattr(math,i))]

This would return the methods whose docstrings include sin:

['acos', 'acosh', 'asin', 'asinh', 'cos', 'cosh', 'isinf', 'sin', 'sinh']

for which you then could run the help() function

Answered By: pandita

pydoc comes with python and can do searches but only in the synopsis lines of available modules. Quoting pydoc --help:

pydoc -k 
    Search for a keyword in the synopsis lines of all available modules.

Note that into pydoc you can perform searches using “/”.

Answered By: Nicolas Barbey

Look in the python folder in the folder: Doc. This folder has the entire downloaded documentation of the python docs from python.org. I know this is a VERY late answer, but it brings up an easy solution.

Answered By: AHuman

This may not have been available at the time the question asked and answered, but python.org now makes all the documentation available online as an archive of HTML files which can be navigated and searched offline: https://docs.python.org/2/download.html

(The link directs to docs for the latest version of 2.x, but you can choose 3.x and older 2.x versions from that page)

Answered By: sabeer

This was mentioned in the comments already: Zeal
is similar to Dash but for Windows/Linux. It uses the same sources as Dash. It’s built using Qt and is available in the repositories for several distros, for Ubuntu there is a PPA. Download it here.

Zeal is a simple offline API documentation browser inspired by Dash (OS X app), available for Linux and Windows.

  • Quickly search documentation using Alt+Space (or customised) hotkey to display Zeal from any place in your workspace.
  • Search in multiple sets of documentation at once.
  • Don’t be dependent on your internet connection.
  • Integrate Zeal with Emacs, Sublime Text, or Vim. See Usage » Editor plugins for details.

It is open source (GPL), development happens on GitHub. Zeal uses the same stylesheets/HTML as the online docs, so everything should look familiar.

An in-browser alternative is devdocs.io. You can access the website even if you are offline, provided that you’ve marked them for local offline storage. You’ll need to enable the Python 2 docs, and then mark them for offline storage here. However, as a longtime user of the online Python docs, I find the custom stylesheet that DevDocs uses a bit distracting.

Answered By: jmiserez
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.