Skip to main content

simple validator for input data (only work for python dict)

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
enum value must be in list or tuple or set
msg your own error message

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.alpha 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.4.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file makesure-0.4.tar.gz.

File metadata

  • Download URL: makesure-0.4.tar.gz
  • Upload date:
  • Size: 3.2 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

Hashes for makesure-0.4.tar.gz
Algorithm Hash digest
SHA256 cfd8d8adac69ec62e2aa72f304bd62907e2ca90be268f3758cb08f86110b4537
MD5 fb3a713e30aa9830dec41fc65bb0db28
BLAKE2b-256 a0631d9bc1a8e03c4f2f4df8b10ba99b558b99ea82b1b039b9d5ad2344085246

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