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 |
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> |
Alpha | string | alpha |
Alpha Numeric | string | alpha_num ,alpha_numeric |
Alpha Num Dash | string | alpha_dash |
Date | string | date |
UUID | string | uuid |
IPV4 | string | ipv4 |
IPV6 | string | ipv6 |
IP | string | ip |
Mac Address | string | mac ,mac_address |
Testing
# install pytest
pip install pytest
# run tests
python -m pytest
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-1.0.0.tar.gz
(8.8 kB
view details)
Built Distribution
File details
Details for the file fastvalidate-1.0.0.tar.gz
.
File metadata
- Download URL: fastvalidate-1.0.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8f23e5daf7598e73b1d993c9e82e333537abeb163e89a20062105e212aec6ba |
|
MD5 | e77f8243c5b1c0d910bd3f4b8650d4b0 |
|
BLAKE2b-256 | c5e6979c051332b7852b467f8f4771a9355364dfdc100c56ecc5deb7d09161d5 |
File details
Details for the file fastvalidate-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: fastvalidate-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 870f7f7377a512333136c669663e9dd4a8b9b7210f5a5b7ad196f5b704c51f1f |
|
MD5 | 71efba925873c79e1e21a91c7de50e13 |
|
BLAKE2b-256 | a2838f4cae3d02149d5f0acdbcfb01bbe6be06854a852510da0333f7b0220da5 |