Skip to main content

Easy validation for python

Project description

Requirements

  • Python 3.6+

Installation & Upgrade

pip install fastvalidate --upgrade

Dictionary Validation

from fastvalidate import Validator

validator = Validator({
    'first_name': 'Mo',
    'last_name': None,
    'age': '5',
    'email': 'mojtabaa.hn@gmail',
    'website': 'yup',
    'languages': ['en', 'fa'],
}, {
    'first_name': 'required|min:3',
    'last_name': 'required|min:3',
    'age': 'required|numeric|gt:10|lt:120',
    'email': 'required|email',
    'website': 'required|url',
    'languages': 'required|list|min:3'
})

validator.validate().errors()
# {
#     'first_name': 'Field length must be at least 3 characters',
#     'last_name': 'Field is required',
#     'age': 'Field must be greater than 10',
#     'email': 'Field must be email',
#     'website': 'Field must be url',
#     'languages': 'Field must have at least 3 items'
# }

Pydantic Validation

from fastvalidate import BaseModel


class User(BaseModel):
    email: str
    website: str

    class Config:
        rules = dict(
            email='required|email|min:3',
            website='required|url|min:3'
        )


user = User(email='whatever', website='whoever')
# ValidationError
# [
#     dict(loc=('email',), msg='Field must be email', type='value_error'),
#     dict(loc=('website',), msg='Field must be url', type='value_error')
# ]

Available Rules

Type Applicable On signature
Boolean string, boolean bool, boolean
Numeric string, integer numeric, int, integer
List string(json), list list, array
Dictionary string(json), dict dict
Email string email
Password string password
RegEx string regex:<pattern>
URL string url
Length string, integer, float, list, dict len:<length>, length:<length>
Min string, integer, float, list, dict min:<threshold>
Max string, integer, float, list, dict max:<threshold>
Choice string choice:<x>,<y>,<z> in:<x>,<y>,<z>
Greater Than int gt:<threshold>
Greater Than Equal int gte:<threshold>
Less Than int lt:<threshold>
Less Than Equal int lte:<threshold>

Testing

# install pytest
pip install pytest

# run tests
python -m pytest

Development

# install requirements
pip install build twine

# Build package
make build

# Push to basalam repository
make push

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

fastvalidate-0.0.5.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

fastvalidate-0.0.5-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file fastvalidate-0.0.5.tar.gz.

File metadata

  • Download URL: fastvalidate-0.0.5.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for fastvalidate-0.0.5.tar.gz
Algorithm Hash digest
SHA256 3c90829dd79c4a7d8be3085ef10c47d41984b5c1fa244d959007e4f2540e92a2
MD5 b2fc59321eb20bae12f72c2e8ac4ce37
BLAKE2b-256 5a61e02bdc8b035e6581c1e89b9251efac0fe49c90e6c8365be3628686649ebe

See more details on using hashes here.

File details

Details for the file fastvalidate-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for fastvalidate-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 83b3cc25a50cb292f78cba67fc41a47f91d21bf3ab70568f04aa5b991da657de
MD5 07b889b3ec2b8bf8aa3e9ca44b64943c
BLAKE2b-256 55f47d245fc8c296b9bc57fa70c6f85fc471e1b620d7f1b8b3a5fbd0a7b1d7c6

See more details on using hashes here.

Supported by

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