Skip to main content

Elicit

Library for writing console (command oriented) user interfaces. It depends only on the Python standard library.

The package makes it easy and quick to create an interactive command oriented tool. The style is similar to embedded systems, such as routers, and POSIX shells. This is not an alternate Python REPL, such as IPython or bpython. You can use it to implement a custom command interface for your application that gets customizable command parsing, custom prompts, help system, and output paging.

The docopt module is built-in, so no additional packages need to be installed.

Some notable features:

  • Commands are defined as class methods.
  • Command classes group commands, and can be nested, providing context-sensitive commands.
  • Implicit paged output (like more).
  • Command completion.
  • Concise prompt string specification, similar to a shell (percent [%] expansions).
  • Colored output formatting and input prompts.
  • Built-in options parsing.
  • Built-in help, that uses the command-method docstring.
  • Wrap any object to interact with it.
  • Modular design. Any component can be subclassed and enhanced.

Also includes some bonus modules:

  • presentation - helper module for using Python in interactive presentations.
  • debugger - enhanced debugger that uses the framework for the user interface.

Command Lines

Just override the elicit.ui.BaseCommands class. Any methods defined with doc strings become a command that can be called. The command gets an arguments parameter that is a docopt-style pre-parsed dictionary of arguments parsed according to the Usage: line in the doc string.

Here's a working example:

from elicit import commands
from elicit import console
from elicit import controller
from elicit import env
from elicit import parser
from elicit import themes
from elicit import ui


class BasicCommands(commands.BaseCommands):

    def mycommand(self, arguments):
        """Perform some function.

        Usage:
            mycommand [-o]
        """
        self._ui.print("got arguments:", arguments)

    def nestedusage(self, arguments):
        """Check nested optional usage.

        Usage:
            nestedusage [<one> [<two>]]
        """
        self._ui.print("got arguments:", arguments)

    # Add as many more commands as you need.


def basic_cli():
    # Create The IO module.
    uio = console.ConsoleIO()

    environment = env.Environ.from_system()
    theme = themes.DefaultTheme()  # The built-in colored theme.

    # Assemble the IO in user interface.
    theui = ui.UserInterface(uio, environment, theme)

    # Create the top-level command set, with the user interface.
    cmd = BasicCommands(theui)

    # Add it to a controller, and command parser.
    ctl = controller.CommandController(cmd)
    p = parser.CommandParser(ctl)

    # Run the CLI using the parser.
    p.interact()

This defines a new command, mycommand, with a singo option -o.

Presentations

The elicit.present subpackage has some functionality useful for interactive presentatations using the Python REPL. Exposes some iTerm features on MacOS.

Thanks to David Beazley for the inspiration.

To invoke interactively, for testing, use:

python3 -iq -m elicit.present.presentation

Debugger

An enhanced debugger that uses this CLI toolkit is also provided. A tool, eldb, is also provided that you can use instead of python3 to run a script, or module, that will enter the debugger if an uncaught exception occurs.

eldb path/to/script.py

or, if you have a package with an if ... __main__: section:

eldb mypackage.mymodule

You can also import the elicit.debugger module in your code and call the post_mortem function, as with pdb.

Some notable features:

  • Colorized UI - stacktrace, prompt, etc.
  • More informative reports, prompt shows current position in stack.
  • Invoke your editor at current point.
  • REPL-like evaluator
  • Enter sub-REPL if desired.
  • Display opcodes.

Download files

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

Source Distribution

elicit-1.6.2.tar.gz (52.4 kB view details)

Uploaded Source

Built Distribution

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

elicit-1.6.2-py3-none-any.whl (122.2 kB view details)

Uploaded Python 3

File details

Details for the file elicit-1.6.2.tar.gz.

File metadata

  • Download URL: elicit-1.6.2.tar.gz
  • Upload date:
  • Size: 52.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for elicit-1.6.2.tar.gz
Algorithm Hash digest
SHA256 2a6f107174ec4e6c06a3a7b0c83fd5a551f30dd306551cfcfbd6b4d466fd0286
MD5 b98f86bbe85d372ff65791e95ba62716
BLAKE2b-256 0474357c9b581b8ed1f4182e056203f6c8483f5b48d2bb11530e6e4780303c0f

See more details on using hashes here.

File details

Details for the file elicit-1.6.2-py3-none-any.whl.

File metadata

  • Download URL: elicit-1.6.2-py3-none-any.whl
  • Upload date:
  • Size: 122.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for elicit-1.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c917371e01b37697ee32a08e63e231ffd73bea02b993fcb0b12e9bb6482072e6
MD5 9bf4115a16e5987f1051652c7a99f26b
BLAKE2b-256 0e70894e8d6deae52a211ec15d15dd84f08cd5e668ea8538fb45016a1bee703d

See more details on using hashes here.

Release history Release notifications | RSS feed

1.7.2

2 files

1.7.1

2 files

1.7.0

2 files

This release

1.6.2 This release

2 files

1.6.1

2 files

1.6.0

2 files

1.5.3

1 file

1.5.2

2 files

1.5.1

2 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