Skip to main content

Data validation for Python, inspired by the Laravel framework.

Project description

Spotlight

Data validation for Python, inspired by the Laravel framework.

Coverage

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|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:

{"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", "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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spotlight-3.3.0.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

spotlight-3.3.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file spotlight-3.3.0.tar.gz.

File metadata

  • Download URL: spotlight-3.3.0.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.0.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.14

File hashes

Hashes for spotlight-3.3.0.tar.gz
Algorithm Hash digest
SHA256 ceb6550fb6d950c4dc9aa375a0bcbb9bcfe34073245721b3ef3d196a9a5a9a5e
MD5 96ecef0759837a2de7c5a40686f8dc2b
BLAKE2b-256 bbaee1ccf9e916d5c062604ad1168237ccfea78a40fb7ccfba186b5240d70eef

See more details on using hashes here.

File details

Details for the file spotlight-3.3.0-py3-none-any.whl.

File metadata

  • Download URL: spotlight-3.3.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.0.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.14

File hashes

Hashes for spotlight-3.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65f9162dbc8fc3396c05f75ffa8b0760cff8c9c806e0d65f41493b2deb52b081
MD5 1471e713ea76e3e88587c38f4293897f
BLAKE2b-256 10973a4cacaa006a531e21c379fd5e186ab86e5c6f992aab3685de2850b1c82c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page