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.


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


Download files

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

Source Distribution

spotlight-2.2.1.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spotlight-2.2.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spotlight-2.2.1.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

File hashes

Hashes for spotlight-2.2.1.tar.gz
Algorithm Hash digest
SHA256 ca7bf0f77901ea97a50239bd60af3da948876ac5c7112da7edef2b76b8155626
MD5 60592f9985f09831f864dc672cda1aec
BLAKE2b-256 b026d3d806f6ac6a26775adee8e18c3a60c5d3ebecd661ceaad9aacdd8052749

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spotlight-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

File hashes

Hashes for spotlight-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eff1de377b5c3f8110add0b8a9ea04980fa1106c2b699c2cf31417f9728f7b49
MD5 7b7398514501679590287cca3ce65dd0
BLAKE2b-256 6005c56346bd7bde63e774d6febeecc3c37d2e85279e35517d508cab41f55f80

See more details on using hashes here.

Supported by

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