Metadata-Version: 1.1
Name: jsonmodels
Version: 1.1.1
Summary: Models to make easier to deal with structures that are to be casted to JSON.
Home-page: https://github.com/beregond/jsonmodels
Author: Szczepan Cieślik
Author-email: szczepan.cieslik@gmail.com
License: BSD
Description: ===========
        JSON models
        ===========
        
        .. image:: https://badge.fury.io/py/jsonmodels.png
            :target: http://badge.fury.io/py/jsonmodels
        
        .. image:: https://travis-ci.org/beregond/jsonmodels.png?branch=master
            :target: https://travis-ci.org/beregond/jsonmodels
        
        .. image:: https://pypip.in/d/jsonmodels/badge.png
            :target: https://crate.io/packages/jsonmodels?version=latest
        
        
        Models to make easier to deal with structures that are to be casted to JSON.
        
        * Free software: BSD license
        * Documentation: http://jsonmodels.rtfd.org.
        
        Features
        --------
        
        * Fully tested with Python 2.7, 3.4 and PyPy.
        
        * Create Django-like models:
        
        .. code-block:: python
        
            from jsonmodels import models, fields
        
        
            class Cat(models.Base):
        
                name = fields.StringField(required=True)
                breed = fields.StringField()
        
        
            class Dog(models.Base):
        
                name = fields.StringField(required=True)
                age = fields.IntField()
        
        
            class Car(models.Base):
        
                registration_number = fields.StringField(required=True)
                engine_capacity = fields.FloatField()
                color = fields.StringField()
        
        
            class Person(models.Base):
        
                name = fields.StringField(required=True)
                surname = fields.StringField(required=True)
                car = fields.EmbeddedField(Car)
                pets = fields.ListField([Cat, Dog])
        
        * Access to values through attributes:
        
        .. code-block:: python
        
            >>> cat = Cat()
            >>> cat.populate(name='Garfield')
            >>> cat.name
            'Garfield'
            >>> cat.breed = 'mongrel'
            >>> cat.breed
            'mongrel'
        
        * Validate models:
        
        .. code-block:: python
        
            >>> person = Person(name='Chuck', surname='Norris')
            >>> person.validate()
            None
        
            >>> dog = Dog()
            >>> dog.validate()
            *** ValidationError: Field "name" is required!
        
        * Cast models to python struct and JSON:
        
        .. code-block:: python
        
            >>> cat = Cat(name='Garfield')
            >>> dog = Dog(name='Dogmeat', age=9)
            >>> car = Car(registration_number='ASDF 777', color='red')
            >>> person = Person(name='Johny', surname='Bravo', pets=[cat, dog])
            >>> person.car = car
            >>> person.to_struct()
            {
                'car': {
                    'color': 'red',
                    'registration_number': 'ASDF 777'
                },
                'surname': 'Bravo',
                'name': 'Johny',
                'pets': [
                    {'name': 'Garfield'},
                    {'age': 9, 'name': 'Dogmeat'}
                ]
            }
        
            >>> import json
            >>> person_json = json.dumps(person.to_struct())
        
        * You don't like to write JSON Schema? Let `jsonmodels` do it for you:
        
        .. code-block:: python
        
            >>> person = Person()
            >>> person.to_json_schema()
            {
                'additionalProperties': False,
                'required': ['surname', 'name'],
                'type': 'object',
                'properties': {
                    'car': {
                        'additionalProperties': False,
                        'required': ['registration_number'],
                        'type': 'object',
                        'properties': {
                            'color': {'type': 'string'},
                            'engine_capacity': {'type': 'float'},
                            'registration_number': {'type': 'string'}
                        }
                    },
                    'surname': {'type': 'string'},
                    'name': {'type': 'string'},
                    'pets': {
                        'items': {
                            'oneOf': [
                                {
                                    'additionalProperties': False,
                                    'required': ['name'],
                                    'type': 'object',
                                    'properties': {
                                        'breed': {'type': 'string'},
                                        'name': {'type': 'string'}
                                    }
                                },
                                {
                                    'additionalProperties': False,
                                    'required': ['name'],
                                    'type': 'object',
                                    'properties': {
                                        'age': {'type': 'integer'},
                                        'name': {'type': 'string'}
                                    }
                                }
                            ]
                        },
                        'type': 'list'
                    }
                }
            }
        
        * Compare JSON schemas:
        
        .. code-block:: python
        
            >>> from jsonmodels.utils import compare_schemas
            >>> schema1 = {'type': 'object'}
            >>> schema2 = {'type': 'list'}
            >>> compare_schemas(schema1, schema1)
            True
            >>> compare_schemas(schema1, schema2)
            False
        
        More
        ----
        
        For more examples and better description see full documentation:
        http://jsonmodels.rtfd.org.
        
        
        
        
        History
        -------
        
        Current
        +++++++
        
        * Added possibility to populate already initialized data to EmbeddedField.
        * Added `compare_schemas` utility.
        
        1.1 (2014-05-19)
        ++++++++++++++++
        
        * Added docs.
        * Added json schema generation.
        * Added tests for PEP8 and complexity.
        * Moved to Python 3.4.
        * Added PEP257 compatibility.
        * Added help text to fields.
        
        1.0.5 (2014-04-14)
        ++++++++++++++++++
        
        * Added data transformers.
        
        1.0.4 (2014-04-13)
        ++++++++++++++++++
        
        * List field now supports simple types.
        
        1.0.3 (2014-04-10)
        ++++++++++++++++++
        
        * Fixed compatibility with Python 3.
        * Fixed `str` and `repr` methods.
        
        1.0.2 (2014-04-03)
        ++++++++++++++++++
        
        * Added deep data initialization.
        
        1.0.1 (2014-04-03)
        ++++++++++++++++++
        
        * Added `populate` method.
        
        1.0 (2014-04-02)
        ++++++++++++++++
        
        * First stable release on PyPI.
        
        0.1.0 (2014-03-17)
        ++++++++++++++++++
        
        * First release on PyPI.
        
Keywords: jsonmodels
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
