Skip to main content

REPL plugin for Click

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sereto_repl-0.3.1.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sereto_repl-0.3.1-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file sereto_repl-0.3.1.tar.gz.

File metadata

  • Download URL: sereto_repl-0.3.1.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for sereto_repl-0.3.1.tar.gz
Algorithm Hash digest
SHA256 ee7296f42d162b472b7f8fbb9e398cdaa10709922980402cc9dd7d3eb935ae65
MD5 90b23fcb93a19d8ea833197d7d892ab0
BLAKE2b-256 d22503d443aaf5ed072daf50f6190e59e505b493306bf1af18d1aa0de554c15e

See more details on using hashes here.

File details

Details for the file sereto_repl-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: sereto_repl-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for sereto_repl-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 42d1e8a6e0083301755eb1c082ac44484ab1915c461ea1cb81c9827515a11a4c
MD5 6e4dab0fbbda56180cbf2380c4d57887
BLAKE2b-256 c2ce0d562e104d5f83cbc19abacade6d41d197409d7e915643ce815d0fa15e6a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page