Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timster/peewee-validates
A simple and flexible model and data validator for Peewee ORM.
https://github.com/timster/peewee-validates
Last synced: 13 days ago
JSON representation
A simple and flexible model and data validator for Peewee ORM.
- Host: GitHub
- URL: https://github.com/timster/peewee-validates
- Owner: timster
- License: mit
- Created: 2016-03-15T19:30:59.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-02-19T13:10:45.000Z (over 1 year ago)
- Last Synced: 2024-09-15T10:24:32.530Z (about 2 months ago)
- Language: Python
- Homepage: https://peewee-validates.readthedocs.io
- Size: 104 KB
- Stars: 18
- Watchers: 2
- Forks: 15
- Open Issues: 5
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
peewee-validates
################A simple and flexible model and data validator for `Peewee ORM `_.
.. image:: http://img.shields.io/travis/timster/peewee-validates.svg?style=flat
:target: http://travis-ci.org/timster/peewee-validates
:alt: Build Status.. image:: http://img.shields.io/coveralls/timster/peewee-validates.svg?style=flat
:target: https://coveralls.io/r/timster/peewee-validates
:alt: Code Coverage.. image:: http://img.shields.io/pypi/v/peewee-validates.svg?style=flat
:target: https://pypi.python.org/pypi/peewee-validates
:alt: Version.. image:: http://img.shields.io/pypi/dm/peewee-validates.svg?style=flat
:target: https://pypi.python.org/pypi/peewee-validates
:alt: Downloads.. image:: https://readthedocs.org/projects/peewee-validates/badge/?version=latest
:target: https://peewee-validates.readthedocs.io
:alt: DocumentationRequirements
============* python >= 3.3
* peewee >= 2.8.2 (including Peewee 3)
* python-dateutil >= 2.5.0Installation
============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:
.. code:: python
import peewee
from peewee_validates import ModelValidatorclass 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': 'This field is required.', 'code': 'Must be a unique value.'}
In fact, there is also a generic validator that does not even require a model:
.. code:: python
from peewee_validates import Validator, StringField
class SimpleValidator(Validator):
name = StringField(required=True, max_length=250)
code = StringField(required=True, max_length=4)validator = SimpleValidator(obj)
validator.validate({'code': 'toolong'})print(validator.errors)
# {'name': 'This field is required.', 'code': 'Must be at most 5 characters.'}
Documentation
=============Check out the `Full Documentation `_ for more details.