Data validation for Python, inspired by the Laravel framework.
Project description
Spotlight
Data validation for Python, inspired by the Laravel framework.
Documentation: https://mdoesburg.github.io/spotlight/
Source Code: https://github.com/mdoesburg/spotlight
Requirements
Installation
Spotlight can be installed via pip:
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:
from spotlight import Validator rules = { "id": "required|int", "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:
{"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:
rules = { "id": ["required", "int"], "email": ["required", "email"], "first_name": ["required", "string"], "last_name": ["required", "string"], "password": ["required", "min:8", "max:255"], }
The full documentation can be found here.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size spotlight-2.2.0-py3-none-any.whl (12.6 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |
Filename, size spotlight-2.2.0.tar.gz (25.0 kB) | File type Source | Python version None | Upload date | Hashes View |
Hashes for spotlight-2.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 817920adf1a1d1a64db85e6387364ef856e254feab24a91c7ca38374e64f6680 |
|
MD5 | 3e451cf4ee5b8b93ec676641702024ff |
|
BLAKE2-256 | 6a99227f6a3ffe33d7992b778b6843f03ca61acf2352be1bbe4dad7239671323 |