Asynchronous Console and Interfaces for asyncio

raw JSON →
0.8.2 verified Sat Apr 25 auth: no python

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.

pip install aioconsole
error ModuleNotFoundError: No module named 'aioconsole'
cause The 'aioconsole' package is not installed in the Python environment.
fix
pip install aioconsole
error ImportError: cannot import name 'ainput' from 'aioconsole'
cause The 'ainput' function is not available in the installed version of 'aioconsole'.
fix
Ensure you have the latest version of 'aioconsole' installed: pip install --upgrade aioconsole
error AttributeError: module 'aioconsole' has no attribute 'apython'
cause The 'apython' script is not an attribute of the 'aioconsole' module; it's a separate command-line tool.
fix
Run 'apython' directly from the command line, not as an import in Python.
error TypeError: 'coroutine' object is not callable
cause Attempting to call an asynchronous function without awaiting it.
fix
Use 'await' when calling asynchronous functions: result = await aioconsole.ainput('Prompt: ')
error RuntimeError: This event loop is already running
cause Trying to run an event loop that is already running, often in interactive environments.
fix
Use 'await' directly in interactive environments or manage the event loop appropriately in scripts.
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.
fix Upgrade your Python environment to 3.8 or newer.
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.
fix Evaluate if a more powerful async-compatible REPL or prompting library better suits your advanced interactive needs.
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.
fix Ensure you are using aioconsole v0.7.1 or newer for more robust handling of standard stream protection.
runtime status import time mem disk
3.10-alpine 0.23s 7.9MB 18.0M
3.10-slim 0.15s 7.9MB 18M
3.11-alpine 0.35s 8.2MB 19.8M
3.11-slim 0.25s 8.2MB 20M
3.12-alpine 0.57s 9.4MB 11.7M
3.12-slim 0.54s 9.4MB 12M
3.13-alpine 0.59s 9.9MB 11.3M
3.13-slim 0.53s 9.9MB 12M
3.9-alpine 0.20s 7.7MB 17.4M
3.9-slim 0.18s 7.7MB 18M

This quickstart demonstrates basic asynchronous input and output using `ainput` and `aprint`. Run this script and type in the console when prompted.

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())