Simple data structure validator
Project description
wvalidate
Introduction
WValidate is a validation library.
Installation
Requirements
- Python 3.8+
pip install wvalidate
Basic usage
Creating a simple string validator
from wvalidate import Validate as v
# creating a validator for string
my_validator = v.string()
my_validator.is_valid("Maria") # => (True, None)
my_validator.is_valid(42) # => (False, ValidatorError)
Creating a dict validator
from wvalidate import Validate as v
user_validator = v.dict({
"name": v.string()
})
user_validator.is_valid({ "name": "Fernanda" }) # => (True, None)
user_validator.is_valid({ "name": 31 }) # => (False, ValidatorError)
Primitives
from wvalidate import Validate as v
# primitive values
v.string()
v.integer()
v.float()
v.numeric()
Strings
from wvalidate import Validate as v
v.string(equal="EQUAL")
v.string(min=1)
v.string(max=5)
v.string(min=2, max=7)
v.email()
Numbers
from wvalidate import Validate as v
v.integer(min=1)
v.integer(max=5)
v.integer(min=2, max=7)
v.float(min=1)
v.float(max=5)
v.float(min=2, max=7)
# valid integers and floats
v.numeric(min=1)
v.numeric(max=5)
v.numeric(min=2, max=7)
Enums
from wvalidate import Validate as v
# A list of any type must be passed
v.enum(["rock", "paper", "scissors"])
v.enum([True, False])
v.enum([5, "FIVE"])
my_validator_enum = v.enum([5, "FIVE"])
my_validator_enum.is_valid(5) # => (True, None)
my_validator_enum.is_valid("SIX") # => (Flase, ValidatorError)
Nullables
from wvalidate import Validate as v
# Any Validator must be passed
v.nullable(v.string())
v.nullable(v.enum([True, False]))
v.nullable(v.dict({
"name": v.string(),
"age": v.integer()
}))
my_validator_nullable = v.nullable(v.string())
my_validator_nullable.is_valid("Maria") # => (True, None)
my_validator_nullable.is_valid(None) # => (True, None)
my_validator_nullable.is_valid(3) # => (Flase, ValidatorError)
Lists
from wvalidate import Validate as v
# Any Validator must be passed
v.list(v.string())
v.list(v.enum([True, False]))
v.list(v.dict({
"name": v.string(),
"age": v.integer()
}))
my_validator_list = v.list(v.string())
my_validator_list.is_valid(["ONE", "TWO", "THREE"]) # => (True, None)
my_validator_list.is_valid(["ONE", "TWO", 3]) # => (Flase, ValidatorError)
Dictionaries
from wvalidate import Validate as v
v.dict({
"name": v.string(),
"price": v.numeric(min=0),
"category": v.enum(["food", "drink"])
})
v.dict({
"name": v.string(),
"price": v.integer(min=0),
"address": {
"city": v.string()
}
})
v.dict({
"users": v.list(
v.dict({
"name": v.string(),
"price": v.integer(min=0),
})
)
})
user_validator = v.dict({
"name": v.string()
})
user_validator.is_valid({ "name": "Fernanda" }) # => (True, None)
user_validator.is_valid({ "name": 31 }) # => (False, ValidatorError)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
wvalidate-0.0.1.tar.gz
(13.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
wvalidate-0.0.1-py3-none-any.whl
(23.9 kB
view details)
File details
Details for the file wvalidate-0.0.1.tar.gz.
File metadata
- Download URL: wvalidate-0.0.1.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
745e3f8037a3e128eb3c26d70c4dd66daa0772cccea691455c08947f086d85c7
|
|
| MD5 |
bebb4b208616cd901e11cb3832f92238
|
|
| BLAKE2b-256 |
c9dc6fa01b7f468dbcc23b01ff6e1102742eaa44ac2ad456a4aa32ecd7406ddf
|
File details
Details for the file wvalidate-0.0.1-py3-none-any.whl.
File metadata
- Download URL: wvalidate-0.0.1-py3-none-any.whl
- Upload date:
- Size: 23.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26e36164d28b8414c6d2c629e3b1a3769410d1650ef0b9bc68b42b368a3dfc23
|
|
| MD5 |
22a359b6feb5b15766e6d6093e179295
|
|
| BLAKE2b-256 |
e65de75976ec75da186898cbcfafc12d51dcba0074d8ddfa87c9a003f5228d1c
|