pystachio
pystachio copied to clipboard
Idea: Value constraints
Often we want to restrict the set of values on a field to a subset of those allowed by the type, and often the best place to do this is the data model definition itself. For example:
class Car(Struct):
model = String
max_speed = Integer().constrain(GreaterThan(10))
serial = Required(String().constrain(Match(r'^[0-9]{7}-[0-9A-F]{3}$')))
goal: serializability: just as the pystachio schema can currently be shipped with the data, constraints should be shippable as well
non-goal: arbitrary code: while it's tempting to just add a callback field, doing so would impair portability
Usage example:
car = Car(max_speed='{{ speed }}').bind(speed=5)
car.interpolate() # should return a failure code.
For inspiration see postgresql CHECK constraints.
@kevints are you in a position to code or review for this? I'm willing to be the complement either way.
@jsirois unfortunately I'm not in a position to do either right now.