Skip to content
Subcommand REPL for click apps
Python Shell Makefile
Branch: master
Clone or download
Latest commit 2d78dc5 Oct 15, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Add example REPL for fast testing. Jul 2, 2017
click_repl Version 0.1.6 Oct 15, 2018
tests add black to stylecheckers Jul 29, 2018
.flake8 add black to stylecheckers Jul 29, 2018
.gitignore ignore pytest cache files Jul 29, 2018
.travis.yml add black to stylecheckers Jul 29, 2018
LICENSE Add license Jul 19, 2015 fix: add license to sdist Aug 4, 2018
Makefile Silence outputs for targets. Jul 2, 2017
README.rst add cli call to README examples (#45) Jul 29, 2018 add black to stylecheckers Jul 29, 2018
tox.ini add missing pypy interpreter Jul 29, 2018



In your click app:

import click
from click_repl import register_repl
def cli():

def hello():
    click.echo("Hello world!")


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
def cli():

def myrepl():
    prompt_kwargs = {
        'history': FileHistory('/etc/myrepl/myrepl-history'),
    repl(click.get_current_context(), prompt_kwargs=prompt_kwargs)


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.


Licensed under the MIT, see LICENSE.

You can’t perform that action at this time.