Skip to content

Commit 036a9d7

Browse files
committed
Better document aioconsole limitations in the readme
1 parent 61bcb23 commit 036a9d7

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

README.rst

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,37 @@ aioconsole_ provides:
1414
* `stream`_ support to serve interfaces instead of using standard streams
1515
* the ``apython`` script to access asyncio code at runtime without modifying the sources
1616

17+
⚠️ Limitations
18+
--------------
19+
20+
Better alternative to ``aioconsole.ainput()``
21+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
23+
A common use case for aioconsole is the async alternative to the builtin `input`_ function.
24+
However, aioconsole_ was written in 2015 and since then the powerful prompt-toolkit_ library has gained better asyncio support.
25+
The recommended way to `prompt in an asyncio application <https://python-prompt-toolkit.readthedocs.io/en/master/pages/asking_for_input.html#prompt-in-an-asyncio-application>`_ is now to use the `prompt_toolkit`_ library:
26+
27+
.. code:: python3
28+
29+
from prompt_toolkit import PromptSession
30+
from prompt_toolkit.patch_stdout import patch_stdout
31+
32+
async def my_coroutine():
33+
session = PromptSession()
34+
while True:
35+
with patch_stdout():
36+
result = await session.prompt_async("Say something: ")
37+
print(f"You said: {result}")
38+
39+
40+
Better python consoles with async support
41+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
43+
The python console exposed by `aioconsole`_ is quite limited compared to modern consoles such as `IPython`_ or `ptpython`_. Luckily, those projects gained greater asyncio support over the years. In particular, the following use cases overlap with `aioconsole`_ capabilities:
44+
45+
- `Embedding a ptpython console in an asyncio program <https://github.com/prompt-toolkit/ptpython/blob/master/examples/asyncio-python-embed.py>`_
46+
- `Using the await syntax in an IPython console <https://ipython.readthedocs.io/en/stable/whatsnew/version7.html#autowait-asynchronous-repl>`_
47+
1748

1849
Requirements
1950
------------
@@ -87,15 +118,6 @@ Documentation
87118
Find more examples in the documentation_ and the `example directory`_.
88119

89120

90-
Limitations
91-
-----------
92-
93-
The python console exposed by `aioconsole`_ is quite limited compared to modern consoles such as `IPython`_ or `ptpython`_. Luckily, those projects gained greater asyncio support over the years. In particular, the following use cases overlap with `aioconsole`_ capabilities:
94-
95-
- `Embedding a ptpython console in an asyncio program <https://github.com/prompt-toolkit/ptpython/blob/master/examples/asyncio-python-embed.py>`_
96-
- `Using the await syntax in an IPython console <https://ipython.readthedocs.io/en/stable/whatsnew/version7.html#autowait-asynchronous-repl>`_
97-
98-
99121
Contact
100122
-------
101123

@@ -114,6 +136,7 @@ Vincent Michel: [email protected]
114136
.. _PyPI: aioconsole_
115137
.. _IPython: https://ipython.readthedocs.io
116138
.. _ptpython: https://github.com/prompt-toolkit/ptpython
139+
.. _prompt-toolkit: https://python-prompt-toolkit.readthedocs.io
117140

118141
.. |docs-badge| image:: https://readthedocs.org/projects/aioconsole/badge/?version=latest
119142
:target: http://aioconsole.readthedocs.io/

0 commit comments

Comments
 (0)