Skip to main content

inp_kwargs

Easily validate user inputs with Python, no hassle required!

A Python library for easy input validation using kwargs. This library helps to easily validate inputs such as integers, strings, and more, without needing to write complex validation logic. Additionally, these functions prevent the program from crashing due to invalid inputs, ensuring a robust and user-friendly experience.

Example

Validating an Integer Input

from inp_kwargs import input_int

# Basic integer validation
# Ensures the program won't crash even if the user enters invalid data (e.g., a string).
test = input_int("Enter a number: ")
print(f"You entered: {test}")

# Request a number between 1 and 100
number = input_int("Enter a number between 1 and 100: ",
                   min_value=1,
                   max_value=100)

print(f"You entered: {number}")

# Request a number with custom error messages
number = input_int("Enter a number: ",
                   min_value=1,
                   max_value=100,
                   min_value_error_message="Error: Must be >= 1.",
                   max_value_error_message="Error: Must be <= 100.")
print(f"You entered: {number}")

Available Functions

1. input_int

Validate integer inputs with customizable criteria.

Parameters:

  • min_value (int, optional): Minimum value allowed.
  • max_value (int, optional): Maximum value allowed.
  • range (list, optional): Restrict input to a specific range of values.
  • allowed_values (list, optional): Accept only specific values.
  • even (bool, optional): Ensure the number is even.
  • odd (bool, optional): Ensure the number is odd.
  • multiple_of (int, optional): Validate input is a multiple of the given number.
  • type_error_message (str, optional): Error message for invalid type.
  • clear_console (bool, optional): Clears the console after each invalid input.

Example:

from inp_kwargs import input_int

number = input_int("Enter a number: ", min_value=1, max_value=10, even=True)
print(f"Validated number: {number}")

2. input_float

Validate float inputs with customizable criteria.

Parameters:

Similar to input_int, but for float values.

Example:

from inp_kwargs import input_float

number = input_float("Enter a decimal number: ", min_value=0.5, max_value=9.9)
print(f"Validated float: {number}")

3. input_str

Validate string inputs with customizable criteria.

Parameters:

  • strip (bool, optional): Remove leading and trailing spaces.
  • min_length (int, optional): Minimum string length.
  • max_length (int, optional): Maximum string length.
  • allowed_characters (str, optional): Restrict characters in input.
  • pattern (str, optional): Validate input using a regex pattern.
  • clear_console (bool, optional): Clears the console after each invalid input.
  • strip_error_message (str, optional): Message when string is empty after trimming.
  • min_length_error_message (str, optional): Error message for short strings.
  • max_length_error_message (str, optional): Error message for long strings.

Example:

from inp_kwargs import input_str

text = input_str("Enter a word: ", min_length=3, max_length=8, strip=True, allowed_characters="abcdefghijklmnopqrstuvwxyz")
print(f"Validated string: {text}")

Function Dictionary

Function Name Purpose Input Type
input_int Validate integer inputs Integer
input_float Validate float inputs Float
input_str Validate string inputs String

Features

  • Customizable validation for integers, floats, and strings.
  • Supports custom error messages or default messages for ease of use.
  • Clears the console between attempts for a clean interface.
  • Handles common validation needs such as ranges, patterns, and allowed values.

Installation

You can install inp_kwargs directly from PyPI:

pip install inp_kwargs

License

MIT License. See the LICENSE file for more details.

Metadata

Release files for inp-kwargs 1.0.2

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

Source distribution (sdist)

Source distribution for inp-kwargs 1.0.2
File Size Uploaded Provenance Actions
inp_kwargs-1.0.2.tar.gz 5.0 kB Without provenance Details for inp_kwargs-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for inp-kwargs 1.0.2
File Interpreter ABI Platform Actions
inp_kwargs-1.0.2-py3-none-any.whl Python 3 none any Details for inp_kwargs-1.0.2-py3-none-any.whl

Total release size: 10.2 kB

Release files / inp_kwargs-1.0.2.tar.gz

Download URL inp_kwargs-1.0.2.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3a5ecdef72e8ad61d7ada09c7469c12c112cd28032409646a54b69ae54f50bb8
BLAKE2b-256 checksum
How to use checksums
8cbf4575c55aede22ce26d9095e173b86777a51380e7274290a0c1e011b37fc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.10.0

Release files / inp_kwargs-1.0.2-py3-none-any.whl

Download URL inp_kwargs-1.0.2-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d7964e6f359b837602ea0e5ccb74429c51ab96d43fe17b62262128597c085fc1
BLAKE2b-256 checksum
How to use checksums
30f745ca75032b7ad147ffa00b9ea166c363ed0bfd3b090ffa2cb09ae276e78b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.10.0

Security for inp-kwargs 1.0.2

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