REPL plugin for Click
Project Links
Meta
Author: Markus Unterwaditzer
Requires Python: >=3.6
Classifiers
Programming Language
- Python :: 3
- Python :: 3 :: Only
- Python :: 3.6
- Python :: 3.7
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
click-repl
Installation
Installation is done via pip:
pip install click-repl
Usage
In your click app:
import click
from click_repl import register_repl
@click.group()
def cli():
pass
@cli.command()
def hello():
click.echo("Hello world!")
register_repl(cli)
cli()
In the shell:
$ my_app repl
> hello
Hello world!
> ^C
$ echo hello | my_app repl
Hello world!
Features not shown:
- Tab-completion.
- The parent context is reused, which means
ctx.obj
persists between subcommands. If you're keeping caches on that object (like I do), using the app's repl instead of the shell is a huge performance win. !
- prefix executes shell commands.
You can use the internal :help
command to explain usage.
Advanced Usage
For more flexibility over how your REPL works you can use the repl
function
directly instead of register_repl
. For example, in your app:
import click
from click_repl import repl
from prompt_toolkit.history import FileHistory
@click.group()
def cli():
pass
@cli.command()
def myrepl():
prompt_kwargs = {
'history': FileHistory('/etc/myrepl/myrepl-history'),
}
repl(click.get_current_context(), prompt_kwargs=prompt_kwargs)
cli()
And then your custom myrepl
command will be available on your CLI, which
will start a REPL which has its history stored in
/etc/myrepl/myrepl-history
and persist between sessions.
Any arguments that can be passed to the python-prompt-toolkit
Prompt class
can be passed in the prompt_kwargs
argument and will be used when
instantiating your Prompt
.
Jun 15, 2023
0.3.0
May 30, 2021
0.2.0
Oct 15, 2018
0.1.6
Aug 04, 2018
0.1.5
May 23, 2018
0.1.4
Jan 09, 2018
0.1.3
May 03, 2017
0.1.2
Jan 23, 2017
0.1.1
Sep 18, 2016
0.1.0