https://github.com/mdoesburg/spotlight
Data validation for Python, inspired by the Laravel framework.
https://github.com/mdoesburg/spotlight
python validate validation
Last synced: about 1 month ago
JSON representation
Data validation for Python, inspired by the Laravel framework.
- Host: GitHub
- URL: https://github.com/mdoesburg/spotlight
- Owner: mdoesburg
- License: mit
- Created: 2019-03-26T13:20:29.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-09-29T03:24:23.000Z (over 2 years ago)
- Last Synced: 2025-11-27T09:11:10.733Z (3 months ago)
- Topics: python, validate, validation
- Language: Python
- Homepage:
- Size: 689 KB
- Stars: 10
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Spotlight
Data validation for Python, inspired by the Laravel framework.
---
**Documentation**: https://mdoesburg.github.io/spotlight/
**Source Code**: https://github.com/mdoesburg/spotlight
---
## Requirements
* [Python 3.6+](https://www.python.org/)
## Installation
Spotlight can be installed via pip:
```bash
pip install spotlight
```
## Example
To validate data, we start by defining validation rules for each field we want to validate. After that, we pass the data and the validation rules into the Validator's validate method.
Lets have a look at a simple example:
```python
from spotlight import Validator
rules = {
"id": "required|integer",
"email": "required|email",
"first_name": "required|string",
"last_name": "required|string",
"password": "required|min:8|max:255",
}
data = {
"id": 1,
"email": "john.doe@example.com",
"first_name": "John",
"last_name": "Doe",
"password": "test",
}
validator = Validator()
errors = validator.validate(data, rules)
```
The validate method will return a dictionary of errors, if any occurred.
In the example above, the validate method will return the following errors:
```python
{"password": ["The password field has to be at least 8 characters."]}
```
Alternatively, validation rules may be specified as lists of rules instead of a single | delimited string:
```python
rules = {
"id": ["required", "integer"],
"email": ["required", "email"],
"first_name": ["required", "string"],
"last_name": ["required", "string"],
"password": ["required", "min:8", "max:255"],
}
```
The full documentation can be found [here](https://mdoesburg.github.io/spotlight/).