Skip to main content

click-repl

Tests License Python - version PyPi - version wheels PyPI - Status PyPI - Downloads

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.

Metadata

Release files for click-repl 0.4.1

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

Source distribution (sdist)

Source distribution for click-repl 0.4.1
File Size Uploaded
click_repl-0.4.1.tar.gz 16.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for click-repl 0.4.1
File Interpreter ABI Platform
click_repl-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 31.4 kB

Release files / click_repl-0.4.1.tar.gz

Download URL click_repl-0.4.1.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c32a1cf6f95e5bd6e92076f81ce24eafd33f2f0ffb0135887e335b8e446d1c0b
BLAKE2b-256 checksum
How to use checksums
2850bea78619ff1fc0fbd61882f64a1302a8abb2ea0b3db92907042d0e362df2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / click_repl-0.4.1-py3-none-any.whl

Download URL click_repl-0.4.1-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5cb10881d4c5ebaa8695eceb69911af3062ee78342812b713564b17aad333eb5
BLAKE2b-256 checksum
How to use checksums
a4f612dc0f2e0159c2b416818b7fedcda15b520043773364a81d7389809a5af5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

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

0.1.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