simple validator for input data (only for python dic)
Project description
makesure
Simple validation for input datas
Installation
pip install makesure
Usage
Create a schema that defines your data and call the function make_sure(your_schema,input_data)
if any validation fails it will raise an exception MakeSureException
otherwise it return the data.
Schemas
A schema is a dict that defines your data.
Keys | Description |
---|---|
required | key must be in data and cannot be None |
min | value grater than or equal to min |
max | value less than or equal to max |
min_len | len of value less than or equal to min_len |
max_len | len of value less than or equal to max_len |
regx | value must satisfy this reguler expressions |
type | data types such as int, str, list, dict, tuple |
sample schema
user_schema = {
'name':{
'required':True,
'type':str
},
'email':{
'type':str,
'required':True,
'regx':Regx.email
},
'age':{
'type':int,
'min':18
}
}
Some Useful Regx
from makesure import Regx
Regx | Description |
---|---|
Regx.email | email regx |
Regx.aplha | only alphabets |
Regx.number | only numbers |
Regx.alphanum | alphanumerics string |
Example
# app.py
from makesure import make_sure, Regx, MakeSureException
user_schema = {
'name':{
'required':True,
'type':str,
},
'age':{
'type':int,
'min':18
},
'email':{
'regx':Regx.email
}
}
data = {
'name':'Your Name',
'age':12,
'email':'asdasd'
}
try:
result = make_sure(user_schema,data)
print(result)
except MakeSureException as e:
print(e)
License
MIT
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
makesure-0.3.tar.gz
(3.1 kB
view details)
File details
Details for the file makesure-0.3.tar.gz
.
File metadata
- Download URL: makesure-0.3.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.8.0 tqdm/4.61.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6bb2817a5388efa15c3675c5764890be9cf0f82c5b0d6b718e2c5fa64bcdc08 |
|
MD5 | 594c48c31342533ec928d2b39ebda608 |
|
BLAKE2b-256 | 864509b0a91c7bd721bb5312b8dd3b187db6ed8d13651fca04b144f0abc3fc12 |