Skip to main content

safer-prompt-toolkit

a wrapper to prompt-toolkit, designed to provide a fallback for some of prompt-toolkit's functionality when operating from a place where prompt-toolkit can't run.

intent:

prompt-toolkit is a powerfull, command line UI, built in to almost every python interpreter. I love using it when asking the user for some input. However, prompt toolkit often complains and crashes when asked to run in certain non-terminal invorments (for example pycharms python console). and I find that this to be a major downside to using prompt toolkit as a minor UI part in some major project, that might somtimes be run in some context that is not the terminal.
after making several projects that needed this functionality, and after deciding that copy pasting this prompt-toolkit fallback project is tedius and unhealthy, I desided to make this thing a project and upload it ot pypi.

Installation

pip install safer-prompt-toolkit

Documentation

after installing, you can import like so:

import safer_prompt_toolkit

and you can send some prompt via:

safer_prompt_toolkit.prompt("some query with validation and completion options")

function documentation

safer_prompt_toolkit.prompt(message,max_failcase_completion_lines=3,max_chars_in_completion_line=150,**prompt_toolkit_kwargs)

use prompt_toolkit's prompt function with a fail-safe
Parameters:

  • message - the prompt messege to be printed to the user, (add \n at the end if you want to get the response in a new line)
  • max_failcase_completion_lines - defaults to 3, in case the regular prompt toolkit fails, max_failcase_completion_lines is the maximum amount of lines in the completion
  • max_chars_in_completion_line - defaults to 150, in case the regular prompt toolkit fails, max_chars_in_completion_line is the maximum amount of chars in a line in the completion
  • **prompt_toolkit_kwargs - any of prompt-toolkits keywords. in case the regular prompt toolkit fails, "validator" and "completer" are used if supplied.

returns:

  • the users response

info:

prompt_toolkit_kwargs allows you to enter some prompt_toolkit.validation.Validator instance. for example 'validator=prompt_toolkit.validation.Validator.DummyValidator()'.
prompt_toolkit_kwargs allows you to enter some prompt_toolkit.completion.Completer instance. for example 'completer=prompt_toolkit.completion.Completer.DummyCompleter()'

call_example:

import safer_prompt_toolkit
import prompt_toolkit.validation,prompt_toolkit.completion

validator1 = prompt_toolkit.validation.DummyValidator() # Could be any prompt_toolkit.validation.Validator instance.
completer1 = prompt_toolkit.completion.DummyCompleter() # Could be any prompt_toolkit.completion.Completer instance.

response = safer_prompt_toolkit.prompt("some prompt message\n",validator=validator1,completer=completer1)
print(f"{response} is the users response.") 

Release files for safer-prompt-toolkit 1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for safer-prompt-toolkit 1.8
File Size Uploaded
safer_prompt_toolkit-1.8.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for safer-prompt-toolkit 1.8
File Interpreter ABI Platform
safer_prompt_toolkit-1.8-py3-none-any.whl Python 3 none any Details

Total release size: 10.8 kB

Release files / safer_prompt_toolkit-1.8.tar.gz

Download URL safer_prompt_toolkit-1.8.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
21b93c298cdf68b6baf014d14068774c0acd75b9dfc4af5b0f10cdb361cb9b8a
BLAKE2b-256 checksum
How to use checksums
9c0c318a24510b203e1551500e2c174b7d5eced91e7ca2df8d5753d62746cb3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.7

Release files / safer_prompt_toolkit-1.8-py3-none-any.whl

Download URL safer_prompt_toolkit-1.8-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d71a1b11856b4bd84549b8693b47363f85f755518ac1a6daced035da26b720e1
BLAKE2b-256 checksum
How to use checksums
179872fa624e276239ecc9d0cee0c759abd507cc6593bbb48f98a687c2dc78ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.7

Release history Release notifications | RSS feed

This release

1.8 This release

2 release files

1.7

2 release files

1.6

2 release files

1.5

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

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