Python REPL is nice. But it’s very basic and in the long run, it’s not convenient to use.
There are a few other alternatives. The most popular one is IPython - it’s the same REPL that runs behind the Jupyter Notebooks, so some of you are probably already familiar with it.
You can install IPython using pip or pipx:
$ pip install ipython # Or even better $ pipx install ipython
I recommend using pipx, because it’s one of those tools that you want to enable globally. You will use IPython in different projects, and you probably want the latest version anyway, instead of having a specific version per project.
So what’s the difference between IPython and Python REPL? The best ones are:
<Tab>in standard Python REPL will, well, insert a Tab (why would anyone want to put a tab after a function name?). Pressing
<Tab>in IPython will trigger autocomplete suggestions, just like in your code editor.
Dynamic object introspection - this is my single, most favorite feature of IPython. You no longer need to search for documentation. Just append (or prepend) a question mark to the name of the function, module, or any Python object, and IPython will show you the docstring of that object.
Do you want to see the complete source code? Use double question mark instead. You don’t have to search where a given function is located (even if it’s installed with pip) - IPython can give you this information right away.
Magic commands - functions that start with % or %%, that you can use to do things like:
And that’s just a few of IPython’s features. If you want to learn more, the IPython documentation can give you a good overview.
If you prefer a more visual demonstration, I gave a presentation about IPython. It’s a 45 minutes long, fast-paced talk where I go through most of its features. Watching it on YouTube is probably better than seeing it live, as you can always stop and test a feature that you find interesting.
I recommend that you start using IPython instead of the default Python REPL. Even if you don’t care about most of the features, the tab-completion, syntax highlighting, and automatic indentation alone will make your life easier.
If you don’t like IPython, there are some other Python REPLs out there. They don’t have as many features as IPython, but they have different features - so maybe you will prefer one of them: