Validators is a lightweight Python library designed for human-friendly data validation without the need for complex schemas or forms. It provides a wide array of simple functions to validate common data types such as email addresses, URLs, IP addresses, and more. On success, validator functions return `True`; on failure, they return a `ValidationFailure` object. The library is actively maintained, with frequent updates to add new validators and improve existing ones.
pip install validatorsVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of `validators.email` and `validators.url`, and how to handle `ValidationFailure` objects.
Upgrade Python to 3.9+ or pin `validators` to `<0.35.0`.
Update your code to use `validators.crypto_addresses.btc_address`.
Check the result in a boolean context (`if result:`) or inspect the `ValidationFailure` object's attributes for details (`if not result: print(result.message)`).
Double-check `pip install validators` and `import validators` to confirm you are using this specific library.
pip install validators
Use the correct function name provided by the library, for example, `validators.email()` for email validation.
Pass the string value you intend to validate as an argument to the function, e.g., `validators.email('test@example.com')`.Always check if the result is `False` (or specifically an instance of `ValidationFailure`) before attempting to access its attributes:
```python
import validators
result = validators.email('test@example.com')
if not result: # This implicitly checks for ValidationFailure
print(f"Validation failed: {result.reason}")
else:
print("Validation succeeded!")
```