Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

create efficent models starting from json schema

Project description


You can use inheritance to create your model:

class User(modeller.Model):
    id = ''
    _schema = {
        'type': 'object',
        'properties': {
            'name': { 'type': 'string' },
            'id': { 'type': 'integer' },
            'age': { 'type': 'integer' },
        'required': [
        # 'additionalProperties': False,

# model will be validated after every instance
me = User(id=01, name='Tommy', surname='Der')

# you can also add additional properties
me.state = 'Italy'




With the schema in types/schema.yaml

    type: string
    type: string
    type: integer
  - name
  - surname
  - age

you can load a model with automatic validation, easy attribute access with dots and no exceptions while trying to access a property defined in the schema.

import yaml
import modeler

schema = yaml.load(open('types/schema.yaml').read())

Model = modeler.make_model(schema=schema,)

Model(name='Tommaso', surname='De Rossi', age=19)


Model validate itself as soon as instantiated, if you want to change this behavior overwrite _on_init method. Model will return None if you try to access a property present in the json schema .properties but not in the object. Model will throw if you try to access a property not present in the object and not in the json schema .properties.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for modeller, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size modeller-0.1.1-py3-none-any.whl (7.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size modeller-0.1.1.tar.gz (5.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page