Skip to main content

Kybra Simple Shell

A lightweight CLI tool for interacting with Python-based Kybra canisters on the Internet Computer (ICP). This acts as a remote REPL, letting you send Python code to your canister and see the output — including stdout, return values, and errors — right in your terminal.

Test PyPI version Python 3.10 License


✨ Features

  • ✅ Seamless remote Python REPL over dfx canister call
  • ✅ Captures stdout, stderr, and return values
  • ✅ Simple commands (:q to quit, :help for guidance)
  • ✅ Packaged as a Python CLI: kybra-simple-shell
  • ✅ Network selection support (local, IC mainnet via --ic, and custom networks)

📦 Installation

pip install kybra-simple-shell

⚡ Quick usage within your canister

# Recommended setup
pyenv install 3.10.7
pyenv local 3.10.7
python -m venv venv
source venv/bin/activate

# Install the package
pip install kybra-simple-shell

Now add the following code to your canister:

from kybra import update, ic

@update
def execute_code(code: str) -> str:
    """Executes Python code and returns the output.

    This is the core function needed for the Kybra Simple Shell to work.
    It captures stdout, stderr, and return values from the executed code.
    """
    import io
    import sys
    import traceback

    stdout = io.StringIO()
    stderr = io.StringIO()
    sys.stdout = stdout
    sys.stderr = stderr

    try:
        # Try to evaluate as an expression
        result = eval(code, globals())
        if result is not None:
            ic.print(repr(result))
    except SyntaxError:
        try:
            # If it's not an expression, execute it as a statement
            # Use the built-in exec function but with a different name to avoid conflict
            exec_builtin = exec
            exec_builtin(code, globals())
        except Exception:
            traceback.print_exc()
    except Exception:
        traceback.print_exc()

    sys.stdout = sys.__stdout__
    sys.stderr = sys.__stderr__
    return stdout.getvalue() + stderr.getvalue()
# Start a local Internet Computer replica
dfx start --clean --background

# Deploy the test canister
dfx deploy

# Use the shell with the test canister directly by name
kybra-simple-shell <MY_CANISTER_ID>              # Local network (default)
# kybra-simple-shell --ic <MY_CANISTER_ID>       # IC mainnet
>>> print("Hello from your canister!")
Hello from your canister!
>>> import my_library_inside_the_canister
>>> a = 42
>>>:q
Goodbye!

Now, connect to canister again and see any changes in memory:

kybra-simple-shell <MY_CANISTER_ID>
>>> print(a)
42

🔍 CLI Features

The shell provides helpful version information on startup (Python, DFX, Kybra versions) and supports commands like :help for guidance and :q to exit.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Release files for kybra-simple-shell 0.1.5

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

Source distribution (sdist)

Source distribution for kybra-simple-shell 0.1.5
File Size Uploaded
kybra_simple_shell-0.1.5.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kybra-simple-shell 0.1.5
File Interpreter ABI Platform
kybra_simple_shell-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 21.4 kB

Release files / kybra_simple_shell-0.1.5.tar.gz

Download URL kybra_simple_shell-0.1.5.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
af1557088dec0ad168d74a70e987a0c3d004c90186e82639d983f929cd3aaf77
BLAKE2b-256 checksum
How to use checksums
d4432097d1dc6f561c95b9a3782fd56136e24defa7b1a6135d8952e42c9cffcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Release files / kybra_simple_shell-0.1.5-py3-none-any.whl

Download URL kybra_simple_shell-0.1.5-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f9e577f3500ed01685ecf11922b1544484f563cd6c750de62f3ab28c7f0f527
BLAKE2b-256 checksum
How to use checksums
702033527db2afbb75ed020c0bfc495fef462bd57f64e573b60042cfe720227b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

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