Skip to main content

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$")

Release files for shella 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shella 1.0.3
File Size Uploaded
shella-1.0.3.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shella 1.0.3
File Interpreter ABI Platform
shella-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 kB

Release files / shella-1.0.3.tar.gz

Download URL shella-1.0.3.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
36f6cecdc34ece09f4ec350cb32e1e5b13e91dd9e850f10e1c243cdf76e07beb
BLAKE2b-256 checksum
How to use checksums
8c283e09fbfa9479ad03da9940b033e99f342cb36ca60169c44105c2783e54a0
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / shella-1.0.3-py3-none-any.whl

Download URL shella-1.0.3-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2240e7aa3f95d5573bf5e1cb64f8ed0d6fa28f9f5b47e2dddbbeec6f44101e18
BLAKE2b-256 checksum
How to use checksums
f6ad8105f1281de22279c4f136113f75f5690835ce7230662c399e03771d610a
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page