Emulating Python's interactive interpreter in asynchronous contexts
Project description
asyncode
Python package for emulating Python's interactive interpreter in asynchronous contexts.
Installation
Use the package manager pip to install asyncode:
pip install asyncode
Dependencies
- Python 3.7+
Usage
This package's external API consists in a two classes, AsyncInteractiveInterpreter
and AsyncInteractiveConsole, which subclass respectively code.InteractiveInterpreter
and code.InteractiveInterpreter
.
These classes are meant to be used in running asynchronous environments. Minimal working code will need to subclass provided classes to implement appropriate functions:
import asyncode
class MyAsyncConsole(asyncode.AsyncInteractiveConsole):
"""AsyncInteractiveConsole adapted to running environment"""
async def write(self, data):
"""Use appropriate method"""
await some_output_coroutine(data)
async def raw_input(self, prompt=""):
"""Use appropriate method"""
if prompt:
await some_output_coroutine(prompt)
data = await some_input_coroutine()
return data
async def run_interpreter():
"""Run an interactive Python interpreter"""
console = MyAsyncConsole()
try:
await console.interact()
except SystemExit:
# Do not exit the whole program!
await some_output_coroutine("Bye!")
Read the docs for more informations.
Contributing
Pull requests are welcome. Do not hesitate to get in touch with me (see below) for any question or suggestion about this project!
License
This work is shared under the MIT license.
© 2020 Loïc Simon (loic.simon@espci.org)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.