Spotlight

raw JSON →
3.4.0 verified Sat May 09 auth: no python

Data validation library for Python, inspired by Laravel's validation system. Current version 3.4.0, supports Python >=3.6. Active development with frequent releases.

pip install spotlight
error ModuleNotFoundError: No module named 'spotlight.validator'
cause Incorrect import path; many tutorials mistakenly use `from spotlight.validator import Validator` instead of `from spotlight import Validator`.
fix
Use from spotlight import Validator.
error KeyError: 'email' when accessing errors
cause Calling `v.errors()` before checking validation; errors are only populated after `passes()` or `fails()` is called.
fix
First call v.passes() or v.fails(), then access v.errors().
gotcha The import path `from spotlight import Validator` is correct, but many online snippets incorrectly use `from spotlight.validator import Validator` which does not exist.
fix Use `from spotlight import Validator`.
gotcha Rule strings are space-separated (e.g., 'required|email'), not comma-separated. Using commas will silently fail.
fix Use pipe-separated rules: `'required|email|min:5'`.
deprecated The `validate()` function (direct call) is deprecated in favor of the `Validator` class for complex rules. It may be removed in future versions.
fix Use `Validator` class with `passes()` or `fails()` methods instead of `validate()`.

Minimal example of creating a Validator instance, checking passes, and retrieving errors.

from spotlight import Validator

v = Validator({'email': 'user@example.com'}, {'email': 'required|email'})
if v.passes():
    print('Validation passed')
else:
    print(v.errors())