This page contains example of field validation on many type of data which could give enough idea about how to use dictify.Field
For text validation, you can use match() or search() with appropriate Regular Expression patterns.
Field().instance(str)
Field().instance(int)
Field().instance(bool)
Using instance()
and verify()
with Python logical and compare operators can verify numbers in many ways.
# 1. number is instance of int or float.
# 2. number is in range [0,10].
Field()\
.instance((int, float))\
.verify(lambda value: 0 <= value <= 10)
Field contains list of days.
Field()\
.listof(str)\
.verify(lambda dates:
set(dates) <= set(['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']))
Field()\
.instance(str)\
.verify(lambda os:
os in ['android', 'ios'])
Field().match('.+@.+')
from datetime import datetime
Field().verify(lambda dt: datetime.fromisoformat(dt))
import io
from PIL import Image
Field()\
.instance(io.BytesIO)\
.verify(lambda img:
Image.open(img).format == 'PNG' or 'JPEG' or 'WEBP' or 'GIF')
import uuid
Field().instance(uuid.UUID)
# UUID in `str` instance.
Field()\
.instance(str)\
.verify(lambda value: uuid.UUID(value))