Skip to main content

Simple Models for Python

Project description

https://travis-ci.org/lamenezes/simple-model.svg?branch=master https://coveralls.io/repos/github/lamenezes/simple-model/badge.svg?branch=master

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


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.6.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file pysimplemodel-0.0.6.tar.gz.

File metadata

File hashes

Hashes for pysimplemodel-0.0.6.tar.gz
Algorithm Hash digest
SHA256 6f9d59a853139ddc4bb8b8e9be40584e8f684e7f288a5a5f30f39fb98f1e6f3b
MD5 50e5288474f8364a9b18260d6a4a04f8
BLAKE2b-256 761e3222f6508908d921a0dd931778f3964940c8561cf8fba5b52c58a5c89bac

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page