# Spotlight
Data validation for Python, inspired by the Laravel framework.
<a href="https://codecov.io/gh/mdoesburg/spotlight" target="_blank">
<img src="https://img.shields.io/codecov/c/github/mdoesburg/spotlight" alt="Coverage">
</a>
---
**Documentation**: <a href="https://mdoesburg.github.io/spotlight/" target="_blank">https://mdoesburg.github.io/spotlight/</a>
**Source Code**: <a href="https://github.com/mdoesburg/spotlight" target="_blank">https://github.com/mdoesburg/spotlight</a>
---
## 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/).
Raw data
{
"_id": null,
"home_page": "https://github.com/mdoesburg/spotlight",
"name": "spotlight",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "spotlight validation validate",
"author": "Michiel Doesburg",
"author_email": "michiel@moddix.com",
"download_url": "https://files.pythonhosted.org/packages/bb/ae/e1ccf9e916d5c062604ad1168237ccfea78a40fb7ccfba186b5240d70eef/spotlight-3.3.0.tar.gz",
"platform": null,
"description": "# Spotlight\nData validation for Python, inspired by the Laravel framework.\n\n<a href=\"https://codecov.io/gh/mdoesburg/spotlight\" target=\"_blank\">\n <img src=\"https://img.shields.io/codecov/c/github/mdoesburg/spotlight\" alt=\"Coverage\">\n</a>\n\n---\n\n**Documentation**: <a href=\"https://mdoesburg.github.io/spotlight/\" target=\"_blank\">https://mdoesburg.github.io/spotlight/</a>\n\n**Source Code**: <a href=\"https://github.com/mdoesburg/spotlight\" target=\"_blank\">https://github.com/mdoesburg/spotlight</a>\n\n---\n\n## Requirements\n* [Python 3.6+](https://www.python.org/)\n\n## Installation\n\nSpotlight can be installed via pip:\n\n```bash\npip install spotlight\n```\n## Example\n\nTo 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. \n\nLets have a look at a simple example:\n\n```python\nfrom spotlight import Validator\n\n\nrules = {\n \"id\": \"required|integer\",\n \"email\": \"required|email\",\n \"first_name\": \"required|string\",\n \"last_name\": \"required|string\",\n \"password\": \"required|min:8|max:255\",\n}\n\ndata = {\n \"id\": 1,\n \"email\": \"john.doe@example.com\",\n \"first_name\": \"John\",\n \"last_name\": \"Doe\",\n \"password\": \"test\",\n}\n\nvalidator = Validator()\nerrors = validator.validate(data, rules)\n```\n\nThe validate method will return a dictionary of errors, if any occurred.\n\nIn the example above, the validate method will return the following errors:\n\n```python\n{\"password\": [\"The password field has to be at least 8 characters.\"]}\n```\n\nAlternatively, validation rules may be specified as lists of rules instead of a single | delimited string:\n\n```python\nrules = {\n \"id\": [\"required\", \"integer\"],\n \"email\": [\"required\", \"email\"],\n \"first_name\": [\"required\", \"string\"],\n \"last_name\": [\"required\", \"string\"],\n \"password\": [\"required\", \"min:8\", \"max:255\"],\n}\n```\n\nThe full documentation can be found [here](https://mdoesburg.github.io/spotlight/).\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Data validation for Python, inspired by the Laravel framework.",
"version": "3.3.0",
"project_urls": {
"Code": "https://github.com/mdoesburg/spotlight",
"Documentation": "https://github.com/mdoesburg/spotlight",
"Homepage": "https://github.com/mdoesburg/spotlight"
},
"split_keywords": [
"spotlight",
"validation",
"validate"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "10973a4cacaa006a531e21c379fd5e186ab86e5c6f992aab3685de2850b1c82c",
"md5": "1471e713ea76e3e88587c38f4293897f",
"sha256": "65f9162dbc8fc3396c05f75ffa8b0760cff8c9c806e0d65f41493b2deb52b081"
},
"downloads": -1,
"filename": "spotlight-3.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1471e713ea76e3e88587c38f4293897f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 13363,
"upload_time": "2023-09-29T03:22:56",
"upload_time_iso_8601": "2023-09-29T03:22:56.691228Z",
"url": "https://files.pythonhosted.org/packages/10/97/3a4cacaa006a531e21c379fd5e186ab86e5c6f992aab3685de2850b1c82c/spotlight-3.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bbaee1ccf9e916d5c062604ad1168237ccfea78a40fb7ccfba186b5240d70eef",
"md5": "96ecef0759837a2de7c5a40686f8dc2b",
"sha256": "ceb6550fb6d950c4dc9aa375a0bcbb9bcfe34073245721b3ef3d196a9a5a9a5e"
},
"downloads": -1,
"filename": "spotlight-3.3.0.tar.gz",
"has_sig": false,
"md5_digest": "96ecef0759837a2de7c5a40686f8dc2b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 31266,
"upload_time": "2023-09-29T03:22:58",
"upload_time_iso_8601": "2023-09-29T03:22:58.358543Z",
"url": "https://files.pythonhosted.org/packages/bb/ae/e1ccf9e916d5c062604ad1168237ccfea78a40fb7ccfba186b5240d70eef/spotlight-3.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-29 03:22:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mdoesburg",
"github_project": "spotlight",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "spotlight"
}