• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

docs/images/H14-Sep-2021-

examples/H14-Sep-2021-462262

ptpython/H14-Sep-2021-5,9224,487

ptpython.egg-info/H03-May-2022-264173

tests/H14-Sep-2021-2314

.gitignoreH A D12-Jan-2020675 5545

CHANGELOGH A D14-Sep-202113.3 KiB625416

LICENSEH A D12-Jan-20201.5 KiB2822

MANIFEST.inH A D12-Jan-2020104 43

PKG-INFOH A D14-Sep-20219.5 KiB264173

README.rstH A D22-Jan-20217 KiB246156

pyproject.tomlH A D29-Jan-2020305 1411

setup.cfgH A D14-Sep-202167 85

setup.pyH A D14-Sep-20211.8 KiB5447

README.rst

1ptpython
2========
3
4|Build Status|  |PyPI|  |License|
5
6*A better Python REPL*
7
8::
9
10    pip install ptpython
11
12.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/example1.png
13
14Ptpython is an advanced Python REPL. It should work on all
15Python versions from 2.6 up to 3.9 and work cross platform (Linux,
16BSD, OS X and Windows).
17
18Note: this version of ptpython requires at least Python 3.6. Install ptpython
192.0.5 for older Python versions.
20
21
22Installation
23************
24
25Install it using pip:
26
27::
28
29    pip install ptpython
30
31Start it by typing ``ptpython``.
32
33
34Features
35********
36
37- Syntax highlighting.
38- Multiline editing (the up arrow works).
39- Autocompletion.
40- Mouse support. [1]
41- Support for color schemes.
42- Support for `bracketed paste <https://cirw.in/blog/bracketed-paste>`_ [2].
43- Both Vi and Emacs key bindings.
44- Support for double width (Chinese) characters.
45- ... and many other things.
46
47
48[1] Disabled by default. (Enable in the menu.)
49
50[2] If the terminal supports it (most terminals do), this allows pasting
51without going into paste mode. It will keep the indentation.
52
53__pt_repr__: A nicer repr with colors
54*************************************
55
56When classes implement a ``__pt_repr__`` method, this will be used instead of
57``__repr__`` for printing. Any `prompt_toolkit "formatted text"
58<https://python-prompt-toolkit.readthedocs.io/en/master/pages/printing_text.html>`_
59can be returned from here. In order to avoid writing a ``__repr__`` as well,
60the ``ptpython.utils.ptrepr_to_repr`` decorator can be applied. For instance:
61
62.. code:: python
63
64    from ptpython.utils import ptrepr_to_repr
65    from prompt_toolkit.formatted_text import HTML
66
67    @ptrepr_to_repr
68    class MyClass:
69        def __pt_repr__(self):
70            return HTML('<yellow>Hello world!</yellow>')
71
72More screenshots
73****************
74
75The configuration menu:
76
77.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/ptpython-menu.png
78
79The history page and its help:
80
81.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/ptpython-history-help.png
82
83Autocompletion:
84
85.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/file-completion.png
86
87
88Embedding the REPL
89******************
90
91Embedding the REPL in any Python application is easy:
92
93.. code:: python
94
95    from ptpython.repl import embed
96    embed(globals(), locals())
97
98You can make ptpython your default Python REPL by creating a `PYTHONSTARTUP file
99<https://docs.python.org/3/tutorial/appendix.html#the-interactive-startup-file>`_ containing code
100like this:
101
102.. code:: python
103
104   import sys
105   try:
106       from ptpython.repl import embed
107   except ImportError:
108       print("ptpython is not available: falling back to standard prompt")
109   else:
110       sys.exit(embed(globals(), locals()))
111
112
113Multiline editing
114*****************
115
116Multi-line editing mode will automatically turn on when you press enter after a
117colon.
118
119To execute the input in multi-line mode, you can either press ``Alt+Enter``, or
120``Esc`` followed by ``Enter``. (If you want the first to work in the OS X
121terminal, you have to check the "Use option as meta key" checkbox in your
122terminal settings. For iTerm2, you have to check "Left option acts as +Esc" in
123the options.)
124
125.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/multiline.png
126
127
128Syntax validation
129*****************
130
131Before execution, ``ptpython`` will see whether the input is syntactically
132correct Python code. If not, it will show a warning, and move the cursor to the
133error.
134
135.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/validation.png
136
137
138Additional features
139*******************
140
141Running system commands: Press ``Meta-!`` in Emacs mode or just ``!`` in Vi
142navigation mode to see the "Shell command" prompt. There you can enter system
143commands without leaving the REPL.
144
145Selecting text: Press ``Control+Space`` in Emacs mode or ``V`` (major V) in Vi
146navigation mode.
147
148
149Configuration
150*************
151
152It is possible to create a ``config.py`` file to customize configuration.
153ptpython will look in an appropriate platform-specific directory via `appdirs
154<https://pypi.org/project/appdirs/>`. See the ``appdirs`` documentation for the
155precise location for your platform. A ``PTPYTHON_CONFIG_HOME`` environment
156variable, if set, can also be used to explicitly override where configuration
157is looked for.
158
159Have a look at this example to see what is possible:
160`config.py <https://github.com/jonathanslenders/ptpython/blob/master/examples/ptpython_config/config.py>`_
161
162
163IPython support
164***************
165
166Run ``ptipython`` (prompt_toolkit - IPython), to get a nice interactive shell
167with all the power that IPython has to offer, like magic functions and shell
168integration. Make sure that IPython has been installed. (``pip install
169ipython``)
170
171.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/ipython.png
172
173This is also available for embedding:
174
175.. code:: python
176
177    from ptpython.ipython.repl import embed
178    embed(globals(), locals())
179
180
181Django support
182**************
183
184`django-extensions <https://github.com/django-extensions/django-extensions>`_
185has a ``shell_plus`` management command. When ``ptpython`` has been installed,
186it will by default use ``ptpython`` or ``ptipython``.
187
188
189PDB
190***
191
192There is an experimental PDB replacement: `ptpdb
193<https://github.com/jonathanslenders/ptpdb>`_.
194
195
196Windows support
197***************
198
199``prompt_toolkit`` and ``ptpython`` works better on Linux and OS X than on
200Windows. Some things might not work, but it is usable:
201
202.. image :: https://github.com/jonathanslenders/ptpython/raw/master/docs/images/windows.png
203
204
205FAQ
206***
207
208**Q**: The ``Ctrl-S`` forward search doesn't work and freezes my terminal.
209
210**A**: Try to run ``stty -ixon`` in your terminal to disable flow control.
211
212**Q**: The ``Meta``-key doesn't work.
213
214**A**: For some terminals you have to enable the Alt-key to act as meta key, but you
215can also type ``Escape`` before any key instead.
216
217
218Alternatives
219************
220
221- `BPython <http://bpython-interpreter.org/downloads.html>`_
222- `IPython <https://ipython.org/>`_
223
224If you find another alternative, you can create an issue and we'll list it
225here. If you find a nice feature somewhere that is missing in ``ptpython``,
226also create a GitHub issue and maybe we'll implement it.
227
228
229Special thanks to
230*****************
231
232- `Pygments <http://pygments.org/>`_: Syntax highlighter.
233- `Jedi <http://jedi.jedidjah.ch/en/latest/>`_: Autocompletion library.
234- `wcwidth <https://github.com/jquast/wcwidth>`_: Determine columns needed for a wide characters.
235- `prompt_toolkit <http://github.com/jonathanslenders/python-prompt-toolkit>`_ for the interface.
236
237.. |Build Status| image:: https://api.travis-ci.org/prompt-toolkit/ptpython.svg?branch=master
238    :target: https://travis-ci.org/prompt-toolkit/ptpython#
239
240.. |License| image:: https://img.shields.io/github/license/prompt-toolkit/ptpython.svg
241    :target: https://github.com/prompt-toolkit/ptpython/blob/master/LICENSE
242
243.. |PyPI| image:: https://pypip.in/version/ptpython/badge.svg
244    :target: https://pypi.python.org/pypi/ptpython/
245    :alt: Latest Version
246