{"id":966,"library":"validators","title":"Validators","description":"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.","status":"active","version":"0.35.0","language":"python","source_language":"en","source_url":"https://github.com/python-validators/validators","tags":["data validation","email validation","url validation","ip address validation","lightweight","schema-less"],"install":[{"cmd":"pip install validators","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Requires Python 3.9 or newer.","package":"python","optional":false}],"imports":[{"note":"All validator functions are directly accessible as attributes of the imported 'validators' module (e.g., validators.email()).","symbol":"validators","correct":"import validators"}],"quickstart":{"code":"import validators\n\nemail_to_check = \"test@example.com\"\nis_valid_email = validators.email(email_to_check)\n\nif is_valid_email:\n    print(f\"'{email_to_check}' is a valid email address.\")\nelse:\n    # ValidationFailure objects evaluate to False in a boolean context\n    print(f\"'{email_to_check}' is not a valid email address. Reason: {is_valid_email.message}\")\n\nurl_to_check = \"http://invalid.domain\"\nis_valid_url = validators.url(url_to_check)\n\nif is_valid_url:\n    print(f\"'{url_to_check}' is a valid URL.\")\nelse:\n    print(f\"'{url_to_check}' is an invalid URL. Reason: {is_valid_url.message}\")","lang":"python","description":"Demonstrates basic usage of `validators.email` and `validators.url`, and how to handle `ValidationFailure` objects."},"warnings":[{"fix":"Upgrade Python to 3.9+ or pin `validators` to `<0.35.0`.","message":"Version 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.","severity":"breaking","affected_versions":"0.35.0+"},{"fix":"Update your code to use `validators.crypto_addresses.btc_address`.","message":"The `btc_address` validator was moved to the `crypto_addresses` submodule. Direct imports or calls to `validators.btc_address` will fail.","severity":"breaking","affected_versions":"0.29.0+"},{"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)`).","message":"Validator 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.","severity":"gotcha","affected_versions":"All"},{"fix":"Double-check `pip install validators` and `import validators` to confirm you are using this specific library.","message":"Be 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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"search_vec":"'activ':61 'add':67 'address':39,42,81 'array':27 'common':33 'complex':19 'data':13,34,74 'design':8 'email':38,76 'exist':72 'failur':52 'form':22 'frequent':64 'friend':12 'function':30,48 'human':11 'human-friend':10 'improv':71 'ip':41,80 'less':86 'librari':7,59 'lightweight':5,83 'maintain':62 'need':17 'new':68 'object':57 'one':73 'provid':24 'python':6 'return':49,54 'schema':20,85 'schema-less':84 'simpl':29 'success':46 'true':50 'type':35 'updat':65 'url':40,78 'valid':1,2,14,32,47,69,75,77,79,82 'validationfailur':56 'wide':26 'without':15","created_at":"2026-03-29T06:09:50.600854+00:00","updated_at":"2026-04-17T00:09:10.872904+00:00","problems":[{"fix":"pip install validators","cause":"The 'validators' library has not been installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'validators'"},{"fix":"Use the correct function name provided by the library, for example, `validators.email()` for email validation.","cause":"An attempt was made to call a validator function using an incorrect or non-existent name.","error":"AttributeError: module 'validators' has no attribute 'mail'"},{"fix":"Pass the string value you intend to validate as an argument to the function, e.g., `validators.email('test@example.com')`.","cause":"A validator function was called without providing the required string argument to be validated.","error":"TypeError: email() missing 1 required positional argument: 'email_address'"},{"fix":"Always check if the result is `False` (or specifically an instance of `ValidationFailure`) before attempting to access its attributes:\n```python\nimport validators\nresult = validators.email('test@example.com')\nif not result: # This implicitly checks for ValidationFailure\n    print(f\"Validation failed: {result.reason}\")\nelse:\n    print(\"Validation succeeded!\")\n```","cause":"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`.","error":"AttributeError: 'bool' object has no attribute 'reason'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.35.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://python-validators.github.io/validators","github":"https://github.com/python-validators/validators","docs":"https://yozachar.github.io/pyvalidators","changelog":"https://github.com/python-validators/validators/blob/master/CHANGES.md","pypi":"https://pypi.org/project/validators/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}