{
  "id": "aiorepl",
  "name": "aiorepl",
  "description": "Provides an asynchronous REPL that can run concurrently with an asyncio, also allowing await expressions.",
  "version": "0.2.4",
  "author": "",
  "license": "MIT",
  "tags": [
    "micropython"
  ],
  "status": "HUMAN_REVIEWED",
  "official": true,
  "source": "https://github.com/micropython/micropython-lib/tree/master/micropython/aiorepl",
  "updatedAt": "2026-08-18T03:55:17.864Z",
  "page": "https://checkmim.com/packages/aiorepl",
  "createdAt": "2025-05-27T04:19:19.510Z",
  "install": {
    "mpremote": "mpremote mip install aiorepl",
    "mip": "import mip; mip.install(\"aiorepl\")"
  },
  "readme": "# aiorepl\n\nThis library provides \"asyncio REPL\", a simple REPL that can be used even\nwhile your program is running, allowing you to inspect program state, create\ntasks, and await asynchronous functions.\n\nThis is inspired by Python's `asyncio` module when run via `python -m asyncio`.\n\n## Background\n\nThe MicroPython REPL is unavailable while your program is running. This\nlibrary runs a background REPL using the asyncio scheduler.\n\nFurthermore, it is not possible to `await` at the main REPL because it does\nnot know about the asyncio scheduler.\n\n## Usage\n\nTo use this library, you need to import the library and then start the REPL task.\n\nFor example, in main.py:\n\n```py\nimport asyncio\nimport aiorepl\n\nasync def demo():\n    await asyncio.sleep_ms(1000)\n    print(\"async demo\")\n\nstate = 20\n\nasync def task1():\n    while state:\n        #print(\"task 1\")\n        await asyncio.sleep_ms(500)\n    print(\"done\")\n\nasync def main():\n    print(\"Starting tasks...\")\n\n    # Start other program tasks.\n    t1 = asyncio.create_task(task1())\n\n    # Start the aiorepl task.\n    repl = asyncio.create_task(aiorepl.task())\n\n    await asyncio.gather(t1, repl)\n\nasyncio.run(main())\n```\n\nAn optional globals dictionary can be passed to `aiorepl.task()`, which allows\nyou to specify what will be in scope for the REPL. By default it uses the\nglobals dictionary from the `__main__` module, which is the same scope as the\nregular REPL (and `main.py`). In the example above, the REPL will be able to\ncall the `demo()` function as well as get/set the `state` variable.\n\nYou can also provide your own dictionary, e.g. `aiorepl.task({\"obj\": obj })`,\nor use the globals dict from the current module, e.g.\n`aiorepl.task(globals())`. Note that you cannot use a class instance's members\ndictionary, e.g. `aiorepl.task(obj.__dict__)`, as this is read-only in\nMicroPython.\n\nInstead of the regular `>>> ` prompt, the asyncio REPL will show `--> `.\n\n```\n--> 1+1\n2\n--> await demo()\nasync demo\n--> state\n20\n--> import myapp.core\n--> state = await myapp.core.query_state()\n--> 1/0\nZeroDivisionError: divide by zero\n--> def foo(x): return x + 1\n--> await asyncio.sleep(foo(3))\n--> \n```\n\nHistory is supported via the up/down arrow keys.\n\n## Cancellation\n\nDuring command editing (the \"R\" phase), pressing Ctrl-C will cancel the current command and display a new prompt, like the regular REPL.\n\nWhile a command is being executed, Ctrl-C will cancel the task that is executing the command. This will have no effect on blocking code (e.g. `time.sleep()`), but this should be rare in an asyncio-based program.\n\nCtrl-D at the asyncio REPL command prompt will terminate the current event loop, which will stop the running program and return to the regular REPL.\n\n## Limitations\n\nThe following features are unsupported:\n\n* Tab completion is not supported (also unsupported in `python -m asyncio`).\n* Multi-line continuation. However you can do single-line definitions of functions, see demo above.\n* Exception tracebacks. Only the exception type and message is shown, see demo above.\n* Emacs shortcuts (e.g. Ctrl-A, Ctrl-E, to move to start/end of line).\n* Unicode handling for input.\n"
}