Skip to main content

A simple python class for creating Read Evaluate Print Line (REPL) interfaces

Project description

Easy REPL

A simple python class for creating Read Evaluate Print Line (REPL) interfaces.

Requirements

This module requires Python 3.8 or higher.

EasyREPL is a pure-Python line editor with no dependency on GNU readline. It works on Linux, macOS, and Windows (Windows uses colorama to enable ANSI escape-sequence processing on the console).

Installation

pip install easyrepl

Usage

This module exposes the REPL class which can be used to quickly create a REPL interface. REPL reads a line of user input via a built-in line editor that allows you to move the cursor with the arrow keys, navigate previous inputs, and edit multi-line input.

from easyrepl import REPL

for line in REPL():
    # do something with line
    print(line)

which will create a simple echoing REPL interface that repeats any line you type into it.

>>> hello
hello
>>> world
world
>>>

The input supports the following key bindings:

  • Ctrl-D: exit REPL (on an empty buffer); otherwise forward-delete
  • Ctrl-L: clear screen
  • Ctrl-R: reverse-i-search through history
  • Left/Right Arrow: move cursor left/right
  • Up/Down Arrow: move up/down within a multi-line input; at the top/bottom edge, navigates previous/next history entry
  • Home / Ctrl-A: move cursor to beginning of line
  • End / Ctrl-E: move cursor to end of line
  • Alt-B / Ctrl-Left: move cursor backward one word
  • Alt-F / Ctrl-Right: move cursor forward one word
  • Ctrl-K: delete from cursor to end of line
  • Ctrl-U: delete from cursor to beginning of line
  • Ctrl-W: delete from cursor to beginning of word
  • Alt-D: delete from cursor to end of word
  • Ctrl-C: abort current input (or quit, if ctrl_c_quit=True)

Multi-line input

Multi-line input can be entered by starting a line with triple quotes (""" or '''), and ending the final line with a matching triple quote. Triple quotes in the middle of a line have no effect.

>>> """
... This is a multi-line input
... that will continue until
... the user enters three quotes
... at the end of a line
... """
This is a multi-line input
that will continue until
the user enters three quotes
at the end of a line
>>>

A single newline is stripped from the beginning and end of the result if present.

Within a multi-line block, the Up and Down arrow keys move the cursor between lines of the buffer. When the cursor is on the first row, Up navigates to the previous history entry; when it's on the last row, Down navigates to the next history entry. Pressing Enter inserts a newline unless the cursor is at the end of the buffer and the block is closed (the line then gets submitted).

API

REPL(*, prompt='>>> ', continuation_prompt='... ', history=None,
     dedup_history=True, ctrl_c_quit=False)
  • prompt: prompt rendered before the first line of each input.
  • continuation_prompt: prompt rendered on every line of a multi-line input after the first.
  • history: path to a file used to load and persist history; None keeps history in-memory only.
  • dedup_history: when True, appending an entry removes any earlier identical entries.
  • ctrl_c_quit: when True, Ctrl-C re-raises KeyboardInterrupt to terminate the REPL.
readl(*, prompt='', continuation_prompt='... ', history=None,
      dedup_history=True, ctrl_c_quit=True) -> str

Read a single line using the REPL editor and return it. Takes the same keyword arguments as REPL (except ctrl_c_quit defaults to True here). History is shared process-wide keyed by history, so repeated readl calls — and a REPL using the same history — participate in the same history.

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

easyrepl-1.0.0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

easyrepl-1.0.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file easyrepl-1.0.0.tar.gz.

File metadata

  • Download URL: easyrepl-1.0.0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for easyrepl-1.0.0.tar.gz
Algorithm Hash digest
SHA256 21883480fdcb718594e651eafcfd45215e31fb82fa6ca4e196f61aedcb684f45
MD5 f624fc4a96f67819d2400f52c3a41f1e
BLAKE2b-256 326c44f5924812a98a4cd55b9e7e951fc7e116addafeabf3ed78bde8a5f3caf2

See more details on using hashes here.

Provenance

The following attestation bundles were made for easyrepl-1.0.0.tar.gz:

Publisher: publish.yml on david-andrew/EasyREPL

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file easyrepl-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: easyrepl-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for easyrepl-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3120c03ca85ba8b8de09ade682e5bb2fb6694ec603be7322b0fa97634a1cc90f
MD5 9641c3a2801075a27479562c871b5df6
BLAKE2b-256 fa801116e87b6390d575cd21e9bfa6651a19800e6cb3d50ebdc7c958411b2d5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for easyrepl-1.0.0-py3-none-any.whl:

Publisher: publish.yml on david-andrew/EasyREPL

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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