You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8933ab2
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.rst
+8-10Lines changed: 8 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,19 +3,17 @@ validators
3
3
4
4
Python data validation for Humans.
5
5
6
+
Python has all kinds of data validation tools, but every one of them seems to
7
+
require defining a schema or form. I wanted to create a simple validation
8
+
library where validating a simple value does not require defining a form or a
9
+
schema.
6
10
7
-
Python has all kinds of data validation tools, but every one of them seems to require defining a schema / form. I wanted to create a simple validation library where validating a simple value does not require defining a form or a schema.
Copy file name to clipboardExpand all lines: docs/index.rst
+27-30Lines changed: 27 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,60 +7,56 @@ Python Data Validation for Humans™.
7
7
Why?
8
8
====
9
9
10
-
Python has all kinds of validation tools, but every one of them requires defining a schema. I wanted to create a simple validation library where validating a simple value does not require defining a form or a schema. Apparently some other guys have felt the same way: http://opensourcehacker.com/2011/07/07/generic-python-validation-frameworks/
10
+
Python has all kinds of validation tools, but every one of them requires
11
+
defining a schema. I wanted to create a simple validation library where
12
+
validating a simple value does not require defining a form or a schema.
13
+
Apparently `some other guys have felt the same way`_.
11
14
12
-
Often I've had for example a case where I just wanted to check if given string is an email. With `validators` this use case becomes as easy as:
Often I've had for example a case where I just wanted to check if given string
19
+
is an email. With ``validators`` this use case becomes as easy as::
15
20
16
21
>>> import validators
17
22
18
-
19
23
>>> validators.email('someone@example.com')
20
24
True
21
25
22
26
23
27
Installation
24
28
============
25
29
26
-
27
-
::
28
-
30
+
You can install ``validators`` using pip::
29
31
30
32
pip install validators
31
33
32
-
33
-
Currently validators supports python versions 2.6, 2.7 and 3.3.
34
+
Currently ``validators`` supports Python versions 2.6, 2.7 and 3.3.
34
35
35
36
36
37
Basic validators
37
38
================
38
39
39
-
Each validator in `validators` is a simple function that takes the value to validate and possibly some additional key-value arguments. Each function returns `True` when validation succeeds and ValidationFailure object when validation fails.
40
-
41
-
ValidationFailure class implements __bool__ method so you can easily check if validation failed:
42
-
43
-
::
44
-
45
-
46
-
if not email('some_bogus_email@@@'):
47
-
# Do something here
48
-
pass
49
-
50
-
51
-
ValidationFailure object also holds all the arguments passed to original function:
52
-
53
-
::
40
+
Each validator in ``validators`` is a simple function that takes the value to
41
+
validate and possibly some additional key-value arguments. Each function returns
42
+
``True`` when validation succeeds and
43
+
:class:`~validators.utils.ValidationFailure` object when validation fails.
54
44
45
+
:class:`~validators.utils.ValidationFailure` class implements ``__bool__``
46
+
method so you can easily check if validation failed::
55
47
56
-
result = number_range(3, min=5)
57
-
if not result:
58
-
result.value
59
-
# 3
48
+
>>> if not validators.email('some_bogus_email@@@'):
49
+
... # Do something here
50
+
... pass
60
51
61
-
result.min
62
-
# 5
52
+
:class:`~validators.utils.ValidationFailure` object also holds all the arguments
0 commit comments