Skip to main content

Inputter - Just getting input


A small library to get user input in a quick and easy way.

Feel free to submit pull requests.

Usage


Use Inputter in your code

Clone or download the Inputter.py file or install via pip.

pip install inputtr
from inputtr import inputter
# Inputter.get_input(prompt, f_constraint: callable = not_empty, f_additional_params=None, max_tries: int = -1) -> Optional:
in_str = inputter.get_input("Prompt: ", constraint_function, [additional, parameters], max_tries=5)

# prompt: The prompt which is shown when input is required.
# f_constraint: Constraint function to check the input against,
#               this function is also allowed to transform the output.
# f_additional_params: List of parameters to supply to the constraint function.
# max_tries: Negative for no limit, otherwise cancel after x and show error.

Flags

# Available flags are:
from inputtr import inputter

inputter.format_prompt = (True / False) # Format the input prompt with badge and color (Default: True)
inputter.silent = (True / False) # Suppresses or enables all output except prompting (Default: False)
inputter.disable_colors = (True / False) # Enables / Disables colored output but keeps badges  (Default: False)
inputter.disable_badges = (True / False) # Enables / Disables badges in output  (Default: False)
inputter.throw_on_constraint_func_error = (True / False) # Changes constraint function error behaviour  (Default: False)

Creating new constraint functions

To create a custom constraint function, your function should follow some simple rules

  1. Accept str as first parameter, this will be the user input
  2. To generate warnings without crashes your function should supply parameter types
  3. The function should return an Optional type and return None if checking was not successful

Your function will be checked before trying to execute it, any minor errors will be output as warnings.

Errors which would crash execution will be output as errors and the get_input() returns None, this behaviour can be changed with the flag mentioned above in which case a RuntimeError is also thrown.

The only exception to this, is the case where you do not supply enough parameters, and the constraint function does not have sufficient default parameters in which case a TypeError is always thrown.

Example:

from inputtr import inputter


def is_integer_in_range(input_str: str, min_val: int, max_val: int) -> Optional[int]:
    try:
        int_val = int(input_str)
        if int_val < min_val or int_val > max_val:
            print_warning(f"Value should be in range {min_val} - {max_val}")
            return None
        return int_val
    except ValueError:
        print_warning("Input is not an integer")
        return None


user_input = Inputter.get_input("Input: ", is_integer_in_range, [0, 100])

As shown in the example to keep the look of printed text the same, you should use the print_error and print_warning function of Inputter.

Changing colors and formatting


Inputter has a selection of colors and modifiers to choose from, the ones available can be accessed via the TermColors class.

Since we are dealing with console output the colors are determined by ANSI escape sequences, to get more information about this read: https://en.wikipedia.org/wiki/ANSI_escape_code

from inputtr import inputter

inputter.info_color = inputter.TermColors.OKBLUE
inputter.error_color = inputter.TermColors.RED
inputter.prompt_color = inputter.TermColors.OKGREEN
inputter.warning_color = inputter.TermColors.YELLOW

All of these colors can of course also be combined with formatting changes.

from inputtr import inputter

Inputter.prompt_color = inputter.TermColors.OKGREEN + inputter.TermColors.BOLD

Metadata

Release files for inputtr 0.0.5

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

Source distribution (sdist)

Source distribution for inputtr 0.0.5
File Size Uploaded Provenance Actions
inputtr-0.0.5.tar.gz 17.0 kB Without provenance Details for inputtr-0.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for inputtr 0.0.5
File Interpreter ABI Platform Actions
inputtr-0.0.5-py3-none-any.whl Python 3 none any Details for inputtr-0.0.5-py3-none-any.whl

Total release size: 34.6 kB

Release files / inputtr-0.0.5.tar.gz

Download URL inputtr-0.0.5.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a8ff30c40f39db8038b41dfc5a4491e30e3784fbf30bd421d774b140de375d12
BLAKE2b-256 checksum
How to use checksums
54267fd5b495281aa085b2ad768bc2b312e4e5787c8bd690ce38df003b0d8539
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.4 tqdm/4.60.0 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.4

Release files / inputtr-0.0.5-py3-none-any.whl

Download URL inputtr-0.0.5-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07ed9a85432638a3c84c334d7deadbb4a0e13545b944189fc0079f18ab9ea9b9
BLAKE2b-256 checksum
How to use checksums
14ebb2ffa0a4c1a8637b831abcbaebb10ff26df69528bf3b8942d9b23d4a6700
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.4 tqdm/4.60.0 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.4

Security for inputtr 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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