Simple and flexible model validator for Peewee ORM.
Project description
A simple and flexible model and data validator for Peewee ORM.
Requirements
python >= 3.3
peewee >= 2.8.0
python-dateutil >= 2.5.0
Installation
This package can be installed using pip:
pip install peewee-validates
Usage
Here’s a quick teaser of what you can do with peewee-validates:
import peewee
from peewee_validates import ModelValidator
class Category(peewee.Model):
code = peewee.IntegerField(unique=True)
name = peewee.CharField(null=False, max_length=250)
obj = Category(code=42)
validator = ModelValidator(obj)
validator.validate()
print(validator.errors)
# {'name': 'required field', 'code': 'must be unique'}
In fact, there is also a generic validator that does not even require a model:
from peewee_validates import Validator, Field
class SimpleValidator(Validator):
name = Field(str, required=True, max_length=250)
code = Field(str, required=True, max_length=4)
validator = SimpleValidator(obj)
validator.validate({'code': 'toolong'})
print(validator.errors)
# {'name': 'required field', 'code': 'must be at most 5 characters'}
Check out the Usage documentation for more details.
Todo
More documentation
More examples
Feedback
This package is very immature. If you have any comments, suggestions, feedback, or issues, please feel free to send me a message or submit an issue on Github.
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
peewee-validates-0.6.0.tar.gz
(7.8 kB
view hashes)
Built Distribution
Close
Hashes for peewee_validates-0.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7174f9aca9743adfb26cbbb21abb74f81931b394dbac5ae82154816285b3c29c |
|
MD5 | ffb191e40e1080d99a9f5e3c7b71be32 |
|
BLAKE2b-256 | 40ae53034fc5e37dc4cbc5b3629c2548acb93930a81b564eb900a648ec3be245 |