Click REPL Plugin

0.3.0 · active · verified Sat Mar 28

click-repl is a Python library that provides a REPL (Read-Eval-Print Loop) plugin for Click-based command-line applications. It allows users to execute multiple commands in a single interactive session, maintaining a shared context. The current version is 0.3.0, released in June 2023, and it generally follows the release cadence of its upstream dependency, Click.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate `click-repl` into a basic Click application. It defines a Click group `cli` with two commands, `hello` and `greet`. The `register_repl(cli)` function adds a 'repl' subcommand to the CLI, enabling an interactive session where `hello` and `greet` can be executed. To run, save as `my_app.py` and execute `python my_app.py repl` in your terminal, then type `hello` or `greet yourname`.

import click
from click_repl import register_repl

@click.group()
def cli():
    """A simple CLI with a REPL."""
    pass

@cli.command()
def hello():
    click.echo("Hello from the REPL!")

@cli.command()
@click.argument('name')
def greet(name):
    click.echo(f"Nice to meet you, {name}!")

if __name__ == '__main__':
    register_repl(cli)
    cli()

view raw JSON →