#!Coding Pedantics
…and opinions you didn't ask for
Coding Pedantics

Python 3 Search Engine

I've been using Python 3 exclusively for a few years now, but when I search for Python API docs, most search engine results point at the Python 2.7 docs. Python 2.7 will be end of life on January 1st, 2020, which is 5 months away as I'm writing this! Why does it keep showing up in my search results!?

Problem

First lets take a look at what happens when you search for a Python API in a general-purpose search engine like Duck Duck Go. I'm not picking on DDG here. Google results have similar problems. Let's say I am using Python 3.7 and I want to lookup the isoformat() API:

Duck Duck Go results frequently point to Python 2 docs.

The only result is for Python 2, but Python 2 is a dead language like Latin! You can click on the Python 2 link, then use a dropdown to switch to Python 3, but this is an extra step—and it won't work if the API changed names in between releases.

Can we do better than this?

Solution

Here's a solution I came up with for Firefox, but similar approaches will work in other browsers. First, we need to register the Python 3 docs as a search engine. Go to https://docs.python.org/3/ and click the ellipsis in the URL bar.

Adding Python 3 docs as a search engine.

Select "Add Search Engine". (By the way, this works because the Python docs implement a standard called OpenSearch.) Now when you are typing queries in the search bar, Firefox will display a Python icon that you can click on to run the query directly against the Python 3 docs.

But we can even improve this even more. In the Firefox search settings, add a shortcut for the Python docs. I called mine py but you could call it py3 if you wanted to be unambiguous or if you also wanted to set up py2 and have quick access to both sets of docs. Since Python has separate search pages for each version, you can even set up keywords like py35, py36, py37, etc. if you want quick access to several different versions.

Adding a search shortcut for Python 3 docs.

Now you can search Python3 docs by prefixing your query with your chosen shortcut, i.e. py datetime.isoformat. This demo video shows the set up in action.

Notice that DuckDuckGo links to the top of the datetime page, whereas the Python 3 search links directly to the function itself, saving even more time. This is a big improvement for my Python development workflow! Let me know what you think.