Package: simpleValidator
simpleValidator===============[![PyPI version](https://badge.fury.io/py/simpleValidator.png)](http://badge.fury.io/py/simpleValidator) [![Build Status](https://travis-ci.org/markleent/simpleValidator.png?branch=master)](https://travis-ci.org/markleent/simpleValidator) [![Coverage Status](https://coveralls.io/repos/markleent/simpleValidator/badge.png?branch=master)](https://coveralls.io/r/markleent/simpleValidator?branch=master) [![Downloads](https://pypip.in/d/simpleValidator/badge.png)](https://pypi.python.org/pypi/simpleValidator/) [![License](https://pypip.in/license/simpleValidator/badge.png)](https://pypi.python.org/pypi/simpleValidator/)A small, extensible python 2 (and 3 compatible !) library to deal with web validations !simpleValidator (or just Validator actually), comes from the need of having a simple and straightforward validation library in python.Sure some heavy players already exists, like WTForm, but take it as both a challenge and having somefun :), it is also inspired by the simplicity of [Laravel](https://github.com/laravel/laravel)'s own validator classThe library is standalone, rules are built the python way, in a module and easy to implement, the library is extensible as well !Where to use it ? in [Flask](https://github.com/mitsuhiko/flask) for example for people who need very simple validationsN.B. : while i have years of experiences in php, i am mostly a newbie in python, this was a good idea to test on, and my very first OSS project as well :)Installing----------1. pip install simpleValidator2. git clone https://github.com/markleent/simpleValidator.gita. cd simpleValidatorb. run python setup.py3. wget https://github.com/markleent/simpleValidator/archive/master.zip (or download through your browser !)a. unzip fileb. cd simpleValidator-*c. run python setup.pyUse case:---------```pythonfrom simplevalidator import Validatormy_items_to_test = {'name': 'myusername','email': 'myfakeemail@fakedomain.com',}my_validation_rules = {'name': 'required','email': 'required|email',}v = Validator()v.make(fields = my_items_to_test, rules = my_validation_rules)### alternatively from the class constructor :v = Validator(fields = my_items_to_test, rules = my_validation_rules)### returns True if the validation failed, False if passedif v.fails():# do somethingelse:# do something else### returns a list of error messagesv.errors()### returns the list of failed validation only (no error message)v.failed()```Custom Validation !-------------------simpleValidator is extensible at runtime ! you can add in your own validation rules and messages !```pythonfrom simplevalidator import Validatormy_items_to_test = {'name': 'myusername','email': 'myfakeemail@fakedomain.com',}my_validation_rules = {'name': 'required|mycustomrule','email': 'required|email',}my_validation_messages = {'mycustomrule': '{0} is not equal to 1 !'}def mycustomrule(value):return value == 1v = Validator()v.extend({'mycustomrule': mycustomrule})v.make(fields = my_items_to_test, rules = my_validation_rules, messages = my_validation_messages)print(v.fails())### outputs Trueprint(v.errors())### outputs ['name is not equal to 1 !']```i18n----simpleValidator supports i18n, through gettext, for now a list of 3 languages are available : English (en), French (fr), Japanese (ja)```pythonfrom simplevalidator import Validator, i18ni18n.switch_language('fr')fields = {'username': ''}rules = {'username': 'required'}v = Validator(fields = fields, rules = rules)print(v.errors())## > ['username est requis']i18n.switch_language('ja')v = Validator(fields = fields, rules = rules)print(v.errors())## > ['usernameは必ず指定してください。']```Rules List==========* required, field to validate must contain a value* email, field must be a valid email* alpha, field must contain alphabetical characters only* alpha_num, field must contain alphabetical characters and/or numbers* alpha_dash, field must contain alphabetical characters, numbers, dashes and underscores* numeric, field must contain a numerical value* integer, field must be an integer only* posinteger, field must be a positive integer only* min, depending on field:- string, size must be at least of min value (ex min = 5, "mystring" is valid)- numerical, value must be at least higher or equal to min value (ex min = 22, 39 is valid)* max, depending on field:- string, size must at most be of max value (ex max = 10, "hello world" is NOT valid)- numerical, value must be lower or equal than max value (ext max = 10, 12 is NOT valid)* between, depending on value:- string, size must be between the boundary values (ex between = (5,10), "hello !" is valid)- numerical, value must be between the 2 values* ip4, field must be a valid ipv4 address* ip6, field must be a valid ipv6 address* date, field must be a valid date, corresponding to a specific template* url, field must be a valid url (https, and port are allowed)To Do------ Add more validation rules with time...- Add support for file validation (mime type, file size etc...)- Add support for json validation (through templates)Is it UnitTested ?------------------All tests files where merged for conveniance in one file that can be either run :1. python setup.py test2. python tests.pyLicense-------Released under a ([MIT](LICENSE)) license.