Registry / serialization / validators

validators

JSON →
library0.35.0pypypi✓ verified 26d ago

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 validators
INSTALL
IMPORT
SIG · VALIDATORS
V
validators
serializationpythonv0.35.0
Install
1.6s avg
Import
71ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.35.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.076s · 18.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.066s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

validators
import validators
All validator functions are directly accessible as attributes of the imported 'validators' module (e.g., validators.email()).

Demonstrates basic usage of `validators.email` and `validators.url`, and how to handle `ValidationFailure` objects.

import validators email_to_check = "test@example.com" is_valid_email = validators.email(email_to_check) if is_valid_email: print(f"'{email_to_check}' is a valid email address.") else: # ValidationFailure objects evaluate to False in a boolean context print(f"'{email_to_check}' is not a valid email address. Reason: {is_valid_email.message}") url_to_check = "http://invalid.domain" is_valid_url = validators.url(url_to_check) if is_valid_url: print(f"'{url_to_check}' is a valid URL.") else: print(f"'{url_to_check}' is an invalid URL. Reason: {is_valid_url.message}")
Debug
Known issues
breakingVersion 0.35.0 dropped support for Python 3.8. Users on Python 3.8 or older must upgrade their Python version or use an older `validators` release.
fix
Upgrade Python to 3.9+ or pin `validators` to `<0.35.0`.
affects: 0.35.0+
breakingThe `btc_address` validator was moved to the `crypto_addresses` submodule. Direct imports or calls to `validators.btc_address` will fail.
fix
Update your code to use `validators.crypto_addresses.btc_address`.
affects: 0.29.0+
gotchaValidator functions return `True` on success or a `ValidationFailure` object on failure. While `ValidationFailure` objects correctly evaluate to `False` in a boolean context, they are not `False` themselves. Access specific error details via attributes like `failure_object.message`, `failure_object.value`, etc.
fix
Check the result in a boolean context (`if result:`) or inspect the `ValidationFailure` object's attributes for details (`if not result: print(result.message)`).
affects: All
gotchaBe mindful of similarly named but distinct libraries like `validator` (for request validation with schema rules) and `validator-collection` (another collection of validation functions with a different API). Ensure you are installing and importing the correct `validators` library.
fix
Double-check `pip install validators` and `import validators` to confirm you are using this specific library.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'validators'
The 'validators' library has not been installed in the current Python environment.
fix
pip install validators
AttributeError: module 'validators' has no attribute 'mail'
An attempt was made to call a validator function using an incorrect or non-existent name.
fix
Use the correct function name provided by the library, for example, `validators.email()` for email validation.
TypeError: email() missing 1 required positional argument: 'email_address'
A validator function was called without providing the required string argument to be validated.
fix
Pass the string value you intend to validate as an argument to the function, e.g., `validators.email('test@example.com')`.
AttributeError: 'bool' object has no attribute 'reason'
The `validators` functions return `True` on successful validation. If validation succeeds, the result is a boolean `True`, not a `ValidationFailure` object, so attempting to access attributes like `reason` (which exist only on `ValidationFailure` objects) will raise an `AttributeError`.
fix
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!")
```
Upgrade
Version history
0.35.0latest on PyPI · released May 1, 2025
Audit
Dependencies
pythonrequiredRequires Python 3.9 or newer.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
validators — pip install validators · libregistry