Skip to main content

A library for easy input validation with kwargs

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inp_kwargs-1.0.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

inp_kwargs-1.0.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file inp_kwargs-1.0.1.tar.gz.

File metadata

  • Download URL: inp_kwargs-1.0.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.0

File hashes

Hashes for inp_kwargs-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7056584c0a8623b6289019f8eeff7875db5b8966e4b7fbde74d0ec14146591a6
MD5 6bea2904c10e5a57c2366a0556e94713
BLAKE2b-256 0344a365c1ad60db1ae4a1ad87a8f6e31eb7d1730ea3d4956d07f917e1f27bf2

See more details on using hashes here.

File details

Details for the file inp_kwargs-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: inp_kwargs-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.0

File hashes

Hashes for inp_kwargs-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 27d5443fb965ad1313e124223b2e7e1f363bddcc9271df696cfa34907e6df47a
MD5 95b9939a73b222b688cd7aabc184358b
BLAKE2b-256 1e06830fb9844c3dd0a2da47d89121745987d0b0f59d6885717f3359a5385763

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page