Skip to main content

Action Completer

Supported Versions Test Status codecov Documentation Status Code Style: Black

A fairly simple method for registering callables as prompt-toolkit completions.

This package provides the basic features to easily construct a custom completer using decorators to reduce the amount of boilerplate needed to build basic tooling through prompt-toolkit. A quick example is provided below, but if you are interested in the available features and patterns you should read through the documentation.

This is a project that I originally created for myself several times when building personal utilities with prompt-toolkit, and figured it might be useful for other people to eventually use or extend. As a side-effect of this being a personal utility, the provided functionality may not exactly fit what you are looking for and the provided tests do not check all edge cases properly yet.

from pathlib import Path

from action_completer import ActionCompleter
from prompt_toolkit.shortcuts import prompt
from prompt_toolkit.completion import PathCompleter
from prompt_toolkit.validation import Validator

completer = ActionCompleter()


@completer.action("cat")
@completer.param(
  PathCompleter(),
  cast=Path,
  validators=[
      Validator.from_callable(
        lambda p: Path(p).is_file(),
        error_message="Path is not an existing file"
      )
  ]
)
def _cat_action(filepath: Path):
  with filepath.open("r") as file_handle:
      print(file_handle.read())


prompt_result = prompt(
  ">>> ",
  completer=completer,
  validator=completer.get_validator()
)
completer.run_action(prompt_result)

Example Recording

Release files for prompt-toolkit-action-completer 1.1.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 prompt-toolkit-action-completer 1.1.1
File Size Uploaded
prompt-toolkit-action-completer-1.1.1.tar.gz 25.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prompt-toolkit-action-completer 1.1.1
File Interpreter ABI Platform
prompt_toolkit_action_completer-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 55.0 kB

Release files / prompt-toolkit-action-completer-1.1.1.tar.gz

Download URL prompt-toolkit-action-completer-1.1.1.tar.gz
Size 25.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8c3e4a344f61cf4c0e3252fe65f0150c7f06b882b2795e71567a2185a6c520bf
BLAKE2b-256 checksum
How to use checksums
2009c0ea90f66ac5b798a87b5c212a087cce3c83cfee56da1f3faa62f5bbb3dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

Release files / prompt_toolkit_action_completer-1.1.1-py3-none-any.whl

Download URL prompt_toolkit_action_completer-1.1.1-py3-none-any.whl
Size 29.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff3d487efc07ecebea5ae851623ec1658c03820b5f058932169de7e360ecf464
BLAKE2b-256 checksum
How to use checksums
3f263d3378d37e1ab031128a3c812d360f7472a843f6ffa2b5a0ab50fb21e0b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

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