README.rst 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. Python Prompt Toolkit
  2. =====================
  3. |Build Status| |PyPI|
  4. ``prompt_toolkit`` is a library for building powerful interactive command lines
  5. and terminal applications in Python.
  6. Read the `documentation on readthedocs
  7. <http://python-prompt-toolkit.readthedocs.io/en/stable/>`_.
  8. Ptpython
  9. ********
  10. `ptpython <http://github.com/jonathanslenders/ptpython/>`_ is an interactive
  11. Python Shell, build on top of prompt_toolkit.
  12. .. image :: https://github.com/jonathanslenders/python-prompt-toolkit/raw/master/docs/images/ptpython.png
  13. prompt_toolkit features
  14. ***********************
  15. ``prompt_toolkit`` could be a replacement for `GNU readline
  16. <http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html>`_, but it can be much
  17. more than that.
  18. Some features:
  19. - Pure Python.
  20. - Syntax highlighting of the input while typing. (For instance, with a Pygments lexer.)
  21. - Multi-line input editing.
  22. - Advanced code completion.
  23. - Both Emacs and Vi key bindings. (Similar to readline.)
  24. - Even some advanced Vi functionality, like named registers and digraphs.
  25. - Reverse and forward incremental search.
  26. - Runs on all Python versions from 2.6 up to 3.5.
  27. - Works well with Unicode double width characters. (Chinese input.)
  28. - Selecting text for copy/paste. (Both Emacs and Vi style.)
  29. - Support for `bracketed paste <https://cirw.in/blog/bracketed-paste>`_.
  30. - Mouse support for cursor positioning and scrolling.
  31. - Auto suggestions. (Like `fish shell <http://fishshell.com/>`_.)
  32. - Multiple input buffers.
  33. - No global state.
  34. - Lightweight, the only dependencies are Pygments, six and wcwidth.
  35. - Runs on Linux, OS X, FreeBSD, OpenBSD and Windows systems.
  36. - And much more...
  37. Feel free to create tickets for bugs and feature requests, and create pull
  38. requests if you have nice patches that you would like to share with others.
  39. About Windows support
  40. *********************
  41. ``prompt_toolkit`` is cross platform, and everything that you build on top
  42. should run fine on both Unix and Windows systems. On Windows, it uses a
  43. different event loop (``WaitForMultipleObjects`` instead of ``select``), and
  44. another input and output system. (Win32 APIs instead of pseudo-terminals and
  45. VT100.)
  46. It's worth noting that the implementation is a "best effort of what is
  47. possible". Both Unix and Windows terminals have their limitations. But in
  48. general, the Unix experience will still be a little better.
  49. For Windows, it's recommended to use either `cmder
  50. <http://cmder.net/>`_ or `conemu <https://conemu.github.io/>`_.
  51. Installation
  52. ************
  53. ::
  54. pip install prompt_toolkit
  55. For Conda, do:
  56. ::
  57. conda install -c https://conda.anaconda.org/conda-forge prompt_toolkit
  58. Getting started
  59. ***************
  60. The most simple example of the library would look like this:
  61. .. code:: python
  62. from prompt_toolkit import prompt
  63. if __name__ == '__main__':
  64. answer = prompt('Give me some input: ')
  65. print('You said: %s' % answer)
  66. For more complex examples, have a look in the ``examples`` directory. All
  67. examples are chosen to demonstrate only one thing. Also, don't be afraid to
  68. look at the source code. The implementation of the ``prompt`` function could be
  69. a good start.
  70. Note for Python 2: all strings are expected to be unicode strings. So, either
  71. put a small ``u`` in front of every string or put ``from __future__ import
  72. unicode_literals`` at the start of the above example.
  73. Projects using prompt_toolkit
  74. *****************************
  75. Shells:
  76. - `ptpython <http://github.com/jonathanslenders/ptpython/>`_: Python REPL
  77. - `ptpdb <http://github.com/jonathanslenders/ptpdb/>`_: Python debugger (pdb replacement)
  78. - `pgcli <http://pgcli.com/>`_: Postgres client.
  79. - `mycli <http://mycli.net>`_: MySql client.
  80. - `wharfee <http://wharfee.com/>`_: A Docker command line.
  81. - `xonsh <http://xon.sh/>`_: A Python-ish, BASHwards-compatible shell.
  82. - `saws <https://github.com/donnemartin/saws>`_: A Supercharged AWS Command Line Interface.
  83. - `cycli <https://github.com/nicolewhite/cycli>`_: A Command Line Interface for Cypher.
  84. - `crash <https://github.com/crate/crash>`_: Crate command line client.
  85. - `vcli <https://github.com/dbcli/vcli>`_: Vertica client.
  86. - `aws-shell <https://github.com/awslabs/aws-shell>`_: An integrated shell for working with the AWS CLI.
  87. - `softlayer-python <https://github.com/softlayer/softlayer-python>`_: A command-line interface to manage various SoftLayer products and services.
  88. - `ipython <http://github.com/ipython/ipython/>`_: The IPython REPL
  89. - `click-repl <https://github.com/click-contrib/click-repl>`_: Subcommand REPL for click apps.
  90. - `haxor-news <https://github.com/donnemartin/haxor-news>`_: A Hacker News CLI.
  91. - `gitsome <https://github.com/donnemartin/gitsome>`_: A Git/Shell Autocompleter with GitHub Integration.
  92. - `http-prompt <https://github.com/eliangcs/http-prompt>`_: An interactive command-line HTTP client.
  93. - `coconut <http://coconut-lang.org/>`_: Functional programming in Python.
  94. - `Ergonomica <https://ergonomica.github.io/>`_: A Bash alternative written in Python.
  95. - `Kube-shell <https://github.com/cloudnativelabs/kube-shell>`_: Kubernetes shell: An integrated shell for working with the Kubernetes CLI
  96. Full screen applications:
  97. - `pymux <http://github.com/jonathanslenders/pymux/>`_: A terminal multiplexer (like tmux) in pure Python.
  98. - `pyvim <http://github.com/jonathanslenders/pyvim/>`_: A Vim clone in pure Python.
  99. (Want your own project to be listed here? Please create a GitHub issue.)
  100. Philosophy
  101. **********
  102. The source code of ``prompt_toolkit`` should be readable, concise and
  103. efficient. We prefer short functions focussing each on one task and for which
  104. the input and output types are clearly specified. We mostly prefer composition
  105. over inheritance, because inheritance can result in too much functionality in
  106. the same object. We prefer immutable objects where possible (objects don't
  107. change after initialisation). Reusability is important. We absolutely refrain
  108. from having a changing global state, it should be possible to have multiple
  109. independent instances of the same code in the same process. The architecture
  110. should be layered: the lower levels operate on primitive operations and data
  111. structures giving -- when correctly combined -- all the possible flexibility;
  112. while at the higher level, there should be a simpler API, ready-to-use and
  113. sufficient for most use cases. Thinking about algorithms and efficiency is
  114. important, but avoid premature optimization.
  115. Special thanks to
  116. *****************
  117. - `Pygments <http://pygments.org/>`_: Syntax highlighter.
  118. - `wcwidth <https://github.com/jquast/wcwidth>`_: Determine columns needed for a wide characters.
  119. .. |Build Status| image:: https://api.travis-ci.org/jonathanslenders/python-prompt-toolkit.svg?branch=master
  120. :target: https://travis-ci.org/jonathanslenders/python-prompt-toolkit#
  121. .. |PyPI| image:: https://img.shields.io/pypi/v/prompt_toolkit.svg
  122. :target: https://pypi.python.org/pypi/prompt-toolkit/
  123. :alt: Latest Version