Asynchronous Console and Interfaces for asyncio
aioconsole provides asynchronous equivalents to built-in functions like input(), print(), and exec() for use within asyncio applications. It includes an interactive loop for running an asynchronous Python console and a script (apython) to access asyncio code at runtime. The library is actively maintained, with regular updates to support newer Python versions.
Warnings
- breaking Python 3.7 support was deprecated in aioconsole v0.7.0. Subsequent versions (0.7.0+) require Python 3.8 or higher. Python 3.7 has reached its official End-of-Life.
- gotcha For complex interactive console applications or rich input prompts, more feature-rich libraries like IPython, ptpython, or prompt_toolkit (for ainput alternatives) are often recommended over aioconsole due to its inherent limitations.
- gotcha Versions prior to 0.7.1 might have had issues with 'more robust protection against the closing of standard streams', which implies potential unexpected behavior if sys.stdin/sys.stdout were closed externally.
Install
-
pip install aioconsole
Imports
- ainput
from aioconsole import ainput
- aprint
from aioconsole import aprint
- aexec
from aioconsole import aexec
- aeval
from aioconsole import aeval
- interact
from aioconsole import interact
Quickstart
import asyncio
from aioconsole import ainput, aprint
async def main():
await aprint("Enter your name:")
name = await ainput("> ")
await aprint(f"Hello, {name}!")
if __name__ == "__main__":
asyncio.run(main())