Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

ptpython

A better Python REPL

Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star half bd79095782ee4930099175e5ce7f4c89fa3ddabcd56fffcc7c74f6f2a2d46b27Star blank 374f33e4d622a2930833db3cbea26b5d03dc44961a6ecab0b9e13276d97d6682 (1 ratings)
Rated 3.5 out of 5
Subscribe to updates I use ptpython


Statistics on ptpython

Number of watchers on Github 2520
Number of open issues 120
Average time to close an issue about 1 month
Main language Python
Average time to merge a PR 4 days
Open pull requests 19+
Closed pull requests 20+
Last commit about 2 years ago
Repo Created almost 5 years ago
Repo Last Updated over 1 year ago
Size 906 KB
Organization / Authorjonathanslenders
Contributors3
Page Updated
Do you use ptpython? Leave a review!
View open issues (120)
View ptpython activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating ptpython for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)
What people are saying about ptpython Leave a review
better docs are needed

ptpython

A better Python REPL

::

pip install ptpython

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/example1.png

|Build Status|

Ptpython is an advanced Python REPL. It should work on all Python versions from 2.6 up to 3.5 and work cross platform (Linux, BSD, OS X and Windows).

Installation


Install it using pip:

::

pip install ptpython

Start it by typing ptpython.

Features


  • Syntax highlighting.
  • Multiline editing (the up arrow works).
  • Autocompletion.
  • Mouse support. [1]
  • Support for color schemes.
  • Support for bracketed paste <https://cirw.in/blog/bracketed-paste>_ [2].
  • Both Vi and Emacs key bindings.
  • Support for double width (Chinese) characters.
  • ... and many other stuff.

[1] Disabled by default. (Enable in the menu.)

[2] If the terminal supports it (most terminals do), this allows pasting without going into paste mode. It will keep the indentation.

More screenshots


The configuration menu:

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/ptpython-menu.png

The history page and its help:

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/ptpython-history-help.png

Autocompletion:

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/file-completion.png

Embedding the REPL


Embedding the REPL in any Python application is easy:

.. code:: python

from ptpython.repl import embed
embed(globals(), locals())

Multiline editing


Multi-line editing mode will automatically turn on when you press enter after a colon.

To execute the input in multi-line mode, you can either press Alt+Enter, or Esc followed by Enter. (If you want the first to work in the OS X terminal, you have to check the Use option as meta key checkbox in your terminal settings. For iTerm2, you have to check Left option acts as +Esc in the options.)

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/multiline.png

Syntax validation


Before execution, ptpython will see whether the input is syntactically correct Python code. If not, it will show a warning, and move the cursor to the error.

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/validation.png

Additional features


Running system commands: Press Meta-! in Emacs mode or just ! in Vi navigation mode to see the Shell command prompt. There you can enter system commands without leaving the REPL.

Selecting text: Press Control+Space in Emacs mode on V (major V) in Vi navigation mode.

Configuration


It is possible to create a ~/.ptpython/config.py file to customize the configuration.

Have a look at this example to see what is possible: config.py <https://github.com/jonathanslenders/ptpython/blob/master/examples/ptpython_config/config.py>_

IPython support


Run ptipython (prompt_toolkit - IPython), to get a nice interactive shell with all the power that IPython has to offer, like magic functions and shell integration. Make sure that IPython has been installed. (pip install ipython)

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/ipython.png

Django support


django-extensions <https://github.com/django-extensions/django-extensions>_ has a shell_plus management command. When ptpython has been installed, it will by default use ptpython or ptipython.

PDB


There is an experimental PDB replacement: ptpdb <https://github.com/jonathanslenders/ptpdb>_.

Windows support


prompt_toolkit and ptpython works better on Linux and OS X than on Windows. Some things might not work, but it is usable:

.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/windows.png

FAQ


Q: The Ctrl-S forward search doesn't work and freezes my terminal.

A: Try to run stty -ixon in your terminal to disable flow control.

Q: The Meta-key doesn't work.

A: For some terminals you have to enable the Alt-key to act as meta key, but you can also type Escape before any key instead.

Alternatives


  • BPython <http://bpython-interpreter.org/downloads.html>_
  • IPython <https://ipython.org/>_

If you find another alternative, you can create an issue and we'll list it here. If you find a nice feature somewhere that is missing in ptpython, also create a GitHub issue and maybe we'll implement it.

Special thanks to


  • Pygments <http://pygments.org/>_: Syntax highlighter.
  • Jedi <http://jedi.readthedocs.io/en/latest/>_: Autocompletion library.
  • Docopt <http://docopt.org/>_: Command-line interface description language.
  • wcwidth <https://github.com/jquast/wcwidth>_: Determine columns needed for a wide characters.
  • prompt_toolkit <http://github.com/jonathanslenders/python-prompt-toolkit>_ for the interface.

.. |Build Status| image:: https://api.travis-ci.org/jonathanslenders/ptpython.svg?branch=master :target: https://travis-ci.org/jonathanslenders/ptpython#

.. |PyPI| image:: https://pypip.in/version/prompt-toolkit/badge.svg :target: https://pypi.python.org/pypi/prompt-toolkit/ :alt: Latest Version

ptpython open issues Ask a question     (View All Issues)
  • almost 3 years Autocomplete for cd command not working correctly when compared to ipython
  • almost 3 years Certain cd commands fail when syntax validation is on
  • almost 3 years Cannot patch __main__.open
  • almost 3 years Wrong python version with python wheels
  • almost 3 years Deprecation warning with autocomplete and RxPy
  • almost 3 years Text starting from hash(#) is rendered as a comment.
  • almost 3 years previous .ptpython symlink breaks initial startup
  • about 3 years Question: What limitation stops ptpython being an editor
  • about 3 years WISH: Scroll to parameter description in docstring
  • about 3 years How do I save it to a file?
  • about 3 years Segfault
  • about 3 years Please use XDG paths for config.py and history by default
  • about 3 years Detecting background color on Windows
  • over 3 years ptipython does not run ipython startup script
  • over 3 years Moving to previous/next word using Ctrl + Left/Right not possible in vi mode
  • over 3 years Bracket highlighting is counterintuitive
  • over 3 years How Do I Map Vi <ESC> to jj?
  • over 3 years ptpython respects "repl.insert_blank_line_after_output = False", but ptipython doesn't appear to ...
  • over 3 years 'Name' tokens hard to see on red-shifted screens
  • over 3 years unperfect behaviour after a PyQtgraph test
  • over 3 years unresponsive after gevent.monkey.patch_all()
  • over 3 years ConEmu configuration
  • over 3 years The second line of long (wrapped around) statements get masked by the 'signature' pop-up ...
  • over 3 years Docstring scrolling with mouse enabled, returns to the top of the docstring ...
  • over 3 years attach ptipython to open jupyter notebook server?
  • over 3 years Customize prompt color
  • over 3 years Add an option to run an asyncio event loop automatically
  • over 3 years Keep environment when exiting ptpython
  • over 3 years Colors are rendered incorrectly
  • over 3 years Support the same options as python and ipython
ptpython open pull requests (View All Pulls)
  • Prompt-toolkit upgrade.
  • Add clipboard configuration option. Resolve #43.
  • Closes issue #55
  • Support user_ns arg for compatibility with start_ipython
  • Make ptipython respect more config changes
  • Contribute a new gevent-compliant event loop (see issue #112)
  • Remove minor python version in entry point.
  • Eliminate extra validation after two newlines.
  • implement XDG Base Directory specification
  • setup.py: extras_require not extra_require
  • Fixing isue 103 nd 83, docstring not scrollable in mouse mode.
  • ptipython: set __file__ when running interactively
  • Suppress all unknown Jedi errors.
  • exception handler for django.ImproperlyConfigured
  • Use Python3Lexer for python 3
  • implement XDG Base Directory specification
  • Switched broken pypip.in badges to shields.io
  • Set last exception in sys module. Fixes #216
  • Don't crash history browser with no history and hitting space
ptpython list of languages used
Other projects in Python