Skip to main content

An asynchronous Interactive shell

Project description

Shella

Shella is a Python module that enables you to interact with your python script using a command line. Provided commands run asynchronously as async functions. In addition to its asynchronous functionality, Shella also provides autocompleting, history, and argument validation features.

Autocompleting enables users to save time by automatically completing commands as they type. History allows users to recall previous commands and reuse them easily. Argument validation ensures that commands are executed with the correct arguments, minimizing errors and increasing efficiency.

How to try

Use Linux (Windows is currently not supported!) and run

pip3 install shella

Here is an example program to you started

import shella
import asyncio

counter = 0

@shella.shell_cmd(["show", "s"], desc="Show counter state")
async def show(args):
    print(f"counter={counter}")

@shella.shell_cmd("set", desc="Set counter state", template="%s", usage="[count]")
async def test(args):
    if len(args) != 2:
        print("Please provide a number")
    global counter
    counter = int(args[1])


async def my_task():
    global counter

    while shella.is_running():
        await asyncio.sleep(1)
        counter += 1
        shella.set_prompt(f"demo{counter:03d}$")


async def main():
    shella_task_ = asyncio.create_task(shella.shell_task())
    my_task_ = asyncio.create_task(my_task())
    shella.set_prompt(f"demo{counter:03d}$")
    await shella_task_
    await my_task_
    print("Good bye!")

asyncio.run(main())

Declaring commands

Commands are declared using the function decorator @shella.shell_cmd(commands,..) which turns a function into a callable. The function must have one argument to which a list of the arguments are passed.

commands a string or list of at most two strings representing the command.

Options

The following arguments can be provided to the function decorator to modify the behaviour of the command:

  • desc: a string with a description, shown in the help list

  • template a string containing a template to match the provided arguments to, availible types are String: %s, Integer: %d, and float: %f

  • usage: String to provide information about the usage of the command, shown on error or arguments that do not match the template

Example

@shella.shell_cmd("foo",template="%d %s")
def set(argv):
    print(argv)
#calling the command as "foo 123 bar" results in print() printing
#["foo",123,"bar"]

Setting the prompt

The prompt can be set at any time using the prompt updates live, which means that it can be dynamically changed during the usage of the program.

shella.set_prompt("shella$")

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

shella-1.0.3.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

shella-1.0.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file shella-1.0.3.tar.gz.

File metadata

  • Download URL: shella-1.0.3.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.5 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.28.1 rfc3986/1.5.0 tqdm/4.64.1 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for shella-1.0.3.tar.gz
Algorithm Hash digest
SHA256 36f6cecdc34ece09f4ec350cb32e1e5b13e91dd9e850f10e1c243cdf76e07beb
MD5 a18b5c7906f3bcc2ba91a2e4e429ebb1
BLAKE2b-256 8c283e09fbfa9479ad03da9940b033e99f342cb36ca60169c44105c2783e54a0

See more details on using hashes here.

File details

Details for the file shella-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: shella-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.5 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.28.1 rfc3986/1.5.0 tqdm/4.64.1 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for shella-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2240e7aa3f95d5573bf5e1cb64f8ed0d6fa28f9f5b47e2dddbbeec6f44101e18
MD5 db1531b3c230749cf48b80c977500393
BLAKE2b-256 f6ad8105f1281de22279c4f136113f75f5690835ce7230662c399e03771d610a

See more details on using hashes here.

Supported by

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