Skip to main content

Emulating Python's interactive interpreter in asynchronous contexts

Project description

asyncode

PyPI PyPI - Python Version PyPI - Wheel Read the Docs Travis CI

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.5 (no CI for Python < 3.8)

Usage

This package's external API consists in two classes, AsyncInteractiveInterpreter and AsyncInteractiveConsole, which subclass respectively code.InteractiveInterpreter and code.InteractiveConsole.

These classes are meant to be used in already running asynchronous contexts. Minimal useful code will need to subclass provided classes to implement specific functions:

import asyncode

class MyAsyncConsole(asyncode.AsyncInteractiveConsole):
    """AsyncInteractiveConsole adapted to running environment"""

    async def write(self, data):
        """Use specific function"""
        await some_output_coroutine(data)

    async def raw_input(self, prompt=""):
        """Use specific functions"""
        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 when sending "exit()" or "quit()"
        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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncode-1.0.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

asyncode-1.0.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file asyncode-1.0.0.tar.gz.

File metadata

  • Download URL: asyncode-1.0.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

File hashes

Hashes for asyncode-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ab8a1629f5e35d26efcc70f5a5d5b571c2abd02d46a865be53476a50b291e2d6
MD5 02d92d504d3cb422eb9a0222a0bad37d
BLAKE2b-256 80c9c44a372a915b6a89cd6fb4da41b96a05a27c0d1dc8f0800f843f12d0c723

See more details on using hashes here.

File details

Details for the file asyncode-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: asyncode-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

File hashes

Hashes for asyncode-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb2e14c2d3753926f3c07444c1a2fb9f78a1751b0e7233c3c663e6473995a395
MD5 a9f2d6120d8e188e179bab58f0c88644
BLAKE2b-256 c9507b53705358434f63f651f379eeb3f2f4cf0609c07de591db9fe53eb34c1d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page