Simple Models for Python
Project description
SimpleModel offers a simple way to handle data using classes instead of a plenty of lists and dicts.
It has simple objectives:
Define your fields easily (just a tuple, not dicts or instances from type classes whatever)
Support for field validation
Serialize to dict
That’s it. If you want something more complex there are plenty of libraries and frameworks that does a lot of cool stuff.
How to install
pip install pysimplemodel
How to use
from simple_model import Model
from simple_model.exceptions import ValidationError
class Person(Model):
fields = ('name', 'age', 'gender', 'height', 'weight')
allow_empty = ('height', 'weight')
def validate_age(self, value):
if 0 > value > 150:
raise ValidationError
def validate_gender(self, value):
if value not in ('M', 'F'):
raise ValidationError
>> person = Person(name='John Doe', age=18, gender='M')
>> person.name
'John Doe'
>> person.validate()
>> person.serialize()
{'name': 'John Doe', 'age': 18, 'gender': 'M', 'height': '', 'weight': ''}
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
pysimplemodel-0.0.7.tar.gz
(2.7 kB
view details)
File details
Details for the file pysimplemodel-0.0.7.tar.gz
.
File metadata
- Download URL: pysimplemodel-0.0.7.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43c6c18dac4819c737fee9616ab77eca691efc211e5ce44a6ae422ed9fe57ffb |
|
MD5 | 73bb0d2a0a33d31b16c30e387bd907b4 |
|
BLAKE2b-256 | 6d3979b68fcb7db933d2b2d08b0cf24d2af0392e6524e5099e2257b2b5c012f5 |