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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

elicit-1.5.3-py3-none-any.whl (122.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: elicit-1.5.3-py3-none-any.whl
  • Upload date:
  • Size: 122.3 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.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for elicit-1.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cfe95690953adff69561d8d15989bfdd2beebe84afb74e3cf5cf37bcfed8c0ff
MD5 5e6e489bb8ef0249083ccf73cd4b5552
BLAKE2b-256 062212b0820d207956b3a1c9bb7db9efa3d8866e376bd05ad352b631fb0fa94d

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

1.6.2

2 files

1.6.1

2 files

1.6.0

2 files

This release

1.5.3 This release

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