jsonmodels


Namejsonmodels JSON
Version 2.7.0 PyPI version JSON
download
home_pagehttps://github.com/jazzband/jsonmodels
SummaryModels to make easier to deal with structures that are converted to, or read from JSON.
upload_time2023-12-17 13:29:14
maintainer
docs_urlNone
authorSzczepan Cieślik
requires_python>=3.8
licenseBSD
keywords jsonmodels
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            ===========
JSON models
===========

.. image:: https://jazzband.co/static/img/badge.svg
   :target: https://jazzband.co/
   :alt: Jazzband

.. image:: https://badge.fury.io/py/jsonmodels.svg
   :target: http://badge.fury.io/py/jsonmodels

.. image:: https://github.com/jazzband/jsonmodels/workflows/Test/badge.svg
   :target: https://github.com/jazzband/jsonmodels/actions
   :alt: Tests

.. image:: https://img.shields.io/pypi/dm/jsonmodels.svg
   :target: https://pypi.python.org/pypi/jsonmodels
   :alt: PyPI

.. image:: https://codecov.io/gh/jazzband/jsonmodels/branch/master/graph/badge.svg
   :target: https://codecov.io/gh/jazzband/jsonmodels
   :alt: Coverage

`jsonmodels` is library to make it easier for you to deal with structures that
are converted to, or read from JSON.

* Free software: BSD license
* Documentation: http://jsonmodels.rtfd.org
* Source: https://github.com/jazzband/jsonmodels

Features
--------

* Fully tested with Python 3.8+.

* Support for PyPy 3.9 and 3.10 (see implementation notes in docs for more details).

* Create Django-like models:

  .. code-block:: python

    from jsonmodels import models, fields, errors, validators


    class Cat(models.Base):

        name = fields.StringField(required=True)
        breed = fields.StringField()
        love_humans = fields.IntField(nullable=True)


    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)
        nickname = fields.StringField(nullable=True)
        car = fields.EmbeddedField(Car)
        pets = fields.ListField([Cat, Dog], nullable=True)

* 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',
        'nickname': None,
        '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': ''},
                    'registration_number': {'type': 'string'}
                }
            },
            'surname': {'type': 'string'},
            'name': {'type': 'string'},
            'nickname': {'type': ['string', 'null']}
            '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': 'number'},
                                'name': {'type': 'string'}
                            }
                        },
                        {
                            'type': 'null'
                        }
                    ]
                },
                'type': 'array'
            }
        }
    }

* Validate models and use validators, that affect generated schema:

  .. code-block:: python

    >>> class Person(models.Base):
    ...
    ...     name = fields.StringField(
    ...         required=True,
    ...         validators=[
    ...             validators.Regex('^[A-Za-z]+$'),
    ...             validators.Length(3, 25),
    ...         ],
    ...     )
    ...     age = fields.IntField(
    ...         nullable=True,
    ...         validators=[
    ...             validators.Min(18),
    ...             validators.Max(101),
    ...         ]
    ...     )
    ...     nickname = fields.StringField(
    ...         required=True,
    ...         nullable=True
    ...     )
    ...

    >>> person = Person()
    >>> person.age = 11
    >>> person.validate()
    *** ValidationError: '11' is lower than minimum ('18').
    >>> person.age = None
    >>> person.validate()
    None

    >>> person.age = 19
    >>> person.name = 'Scott_'
    >>> person.validate()
    *** ValidationError: Value "Scott_" did not match pattern "^[A-Za-z]+$".

    >>> person.name = 'Scott'
    >>> person.validate()
    None

    >>> person.nickname = None
    >>> person.validate()
    *** ValidationError: Field is required!

    >>> person.to_json_schema()
    {
        "additionalProperties": false,
        "properties": {
            "age": {
                "maximum": 101,
                "minimum": 18,
                "type": ["number", "null"]
            },
            "name": {
                "maxLength": 25,
                "minLength": 3,
                "pattern": "/^[A-Za-z]+$/",
                "type": "string"
            },
            "nickname": {,
                "type": ["string", "null"]
            }
        },
        "required": [
            "nickname",
            "name"
        ],
        "type": "object"
    }

  You can also validate scalars, when needed:

  .. code-block:: python

    >>> class Person(models.Base):
    ...
    ...     name = fields.StringField(
    ...         required=True,
    ...         validators=[
    ...             validators.Regex('^[A-Za-z]+$'),
    ...             validators.Length(3, 25),
    ...         ],
    ...     )
    ...     age = fields.IntField(
    ...         nullable=True,
    ...         validators=[
    ...             validators.Min(18),
    ...             validators.Max(101),
    ...         ]
    ...     )
    ...     nickname = fields.StringField(
    ...         required=True,
    ...         nullable=True
    ...     )
    ...

    >>> def only_odd_numbers(item):
    ... if item % 2 != 1:
    ...    raise validators.ValidationError("Only odd numbers are accepted")
    ...
    >>> class Person(models.Base):
    ... lucky_numbers = fields.ListField(int, item_validators=[only_odd_numbers])
    ... item_validator_str = fields.ListField(
    ...        str,
    ...        item_validators=[validators.Length(10, 20), validators.Regex(r"\w+")],
    ...        validators=[validators.Length(1, 2)],
    ...    )
    ...
    >>> Person.to_json_schema()
    {
        "type": "object",
        "additionalProperties": false,
        "properties": {
            "item_validator_str": {
                "type": "array",
                "items": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 20,
                    "pattern": "/\\w+/"
                },
                "minItems": 1,
                "maxItems": 2
            },
            "lucky_numbers": {
                "type": "array",
                "items": {
                    "type": "number"
                }
            }
        }
    }

(Note that `only_odd_numbers` did not modify schema, since only class based validators are
able to do that, though it will still work as expected in python. Use class based validators
that can be expressed in json schema if you want to be 100% correct on schema side.)

* Lazy loading, best for circular references:

  .. code-block:: python

    >>> class Primary(models.Base):
    ...
    ...     name = fields.StringField()
    ...     secondary = fields.EmbeddedField('Secondary')

    >>> class Secondary(models.Base):
    ...
    ...    data = fields.IntField()
    ...    first = fields.EmbeddedField('Primary')

  You can use either `Model`, full path `path.to.Model` or relative imports
  `.Model` or `...Model`.

* Using definitions to generate schema for circular references:

  .. code-block:: python

    >>> class File(models.Base):
    ...
    ...     name = fields.StringField()
    ...     size = fields.FloatField()

    >>> class Directory(models.Base):
    ...
    ...     name = fields.StringField()
    ...     children = fields.ListField(['Directory', File])

    >>> class Filesystem(models.Base):
    ...
    ...     name = fields.StringField()
    ...     children = fields.ListField([Directory, File])

    >>> Filesystem.to_json_schema()
    {
        "type": "object",
        "properties": {
            "name": {"type": "string"}
            "children": {
                "items": {
                    "oneOf": [
                        "#/definitions/directory",
                        "#/definitions/file"
                    ]
                },
                "type": "array"
            }
        },
        "additionalProperties": false,
        "definitions": {
            "directory": {
                "additionalProperties": false,
                "properties": {
                    "children": {
                        "items": {
                            "oneOf": [
                                "#/definitions/directory",
                                "#/definitions/file"
                            ]
                        },
                        "type": "array"
                    },
                    "name": {"type": "string"}
                },
                "type": "object"
            },
            "file": {
                "additionalProperties": false,
                "properties": {
                    "name": {"type": "string"},
                    "size": {"type": "number"}
                },
                "type": "object"
            }
        }
    }

* Dealing with schemaless data

(Plese note that using schemaless fields can cause your models to get out of control - especially if
you are the one responsible for data schema. On the other hand there is usually the case when incomming
data are with no schema defined and schemaless fields are the way to go.)

  .. code-block:: python

    >>> class Event(models.Base):
    ...
    ...     name = fields.StringField()
    ...     size = fields.FloatField()
    ...     extra = fields.DictField()

    >>> Event.to_json_schema()
    {
        "type": "object",
        "additionalProperties": false,
        "properties": {
            "extra": {
                "type": "object"
            },
            "name": {
                "type": "string"
            },
            "size": {
                "type": "float"
            }
        }
    }

`DictField` allow to pass any dict of values (`"type": "object"`), but note, that it will not make any validation
on values except for the dict type.

* Compare JSON schemas:

  .. code-block:: python

    >>> from jsonmodels.utils import compare_schemas
    >>> schema1 = {'type': 'object'}
    >>> schema2 = {'type': 'array'}
    >>> 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
-------

2.7.0 (2023-12-17)
++++++++++++++++++

* Added Python 3.12, PyPy 3.9 and 3.10 support.
* Removed Python 3.7 and PyPy 3.8 support.

2.6.0 (2022-10-14)
++++++++++++++++++

* Removed Python 3.6 support.
* Added support for Python 3.11.

2.5.1 (2022-06-16)
++++++++++++++++++

* Specified PyPy version to PyPy 3.8.
* Added support for Python 3.10.

2.5.0 (2021-07-26)
++++++++++++++++++

* Improvied error messages for field validation errors.
* Allowed to validate non model list items.
* Added DictField.

2.4.1 (2021-02-19)
++++++++++++++++++

* Added Python 3.8 and 3.9 support.
* Removed Python 2.7, 3.3 and 3.5 support.

2.4 (2018-12-01)
++++++++++++++++

* Fixed length validator.
* Added Python 3.7 support.

2.3 (2018-02-04)
++++++++++++++++

* Added name mapping for fields.
* Added value parsing to IntField.
* Fixed bug with ECMA regex flags recognition.

2.2 (2017-08-21)
++++++++++++++++

* Fixed time fields, when value is not required.
* Dropped support for python 2.6
* Added support for python 3.6
* Added nullable param for fields.
* Improved model representation.

2.1.5 (2017-02-01)
++++++++++++++++++

* Fixed DateTimefield error when value is None.
* Fixed comparing models without required values.

2.1.4 (2017-01-24)
++++++++++++++++++

* Allow to compare models based on their type and fields (rather than their
  reference).

2.1.3 (2017-01-16)
++++++++++++++++++

* Fixed generated schema.
* Improved JSON serialization.

2.1.2 (2016-01-06)
++++++++++++++++++

* Fixed memory leak.

2.1.1 (2015-11-15)
++++++++++++++++++

* Added support for Python 2.6, 3.2 and 3.5.

2.1 (2015-11-02)
++++++++++++++++

* Added lazy loading of types.
* Added schema generation for circular models.
* Improved readability of validation error.
* Fixed structure generation for list field.

2.0.1 (2014-11-15)
++++++++++++++++++

* Fixed schema generation for primitives.

2.0 (2014-11-14)
++++++++++++++++

* Fields now are descriptors.
* Empty required fields are still validated only during explicite validations.

Backward compatibility breaks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* Renamed _types to types in fields.
* Renamed _items_types to items_types in ListField.
* Removed data transformers.
* Renamed module `error` to `errors`.
* Removed explicit validation - validation occurs at assign time.
* Renamed `get_value_replacement` to `get_default_value`.
* Renamed modules `utils` to `utilities`.

1.4 (2014-07-22)
++++++++++++++++

* Allowed validators to modify generated schema.
* Added validator for maximum value.
* Added utilities to convert regular expressions between Python and ECMA
  formats.
* Added validator for regex.
* Added validator for minimum value.
* By default "validators" property of field is an empty list.

1.3.1 (2014-07-13)
++++++++++++++++++

* Fixed generation of schema for BoolField.

1.3 (2014-07-13)
++++++++++++++++

* Added new fields (BoolField, TimeField, DateField and DateTimeField).
* ListField is always not required.
* Schema can be now generated from class itself (not from an instance).

1.2 (2014-06-18)
++++++++++++++++

* Fixed values population, when value is not dictionary.
* Added custom validators.
* Added tool for schema comparison.

1.1.1 (2014-06-07)
++++++++++++++++++

* 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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jazzband/jsonmodels",
    "name": "jsonmodels",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "jsonmodels",
    "author": "Szczepan Cie\u015blik",
    "author_email": "szczepan.cieslik@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/fe/f7/77d39f85afc8928e66737ad2ca754a2539a8202abafb5079fc36e1875bc4/jsonmodels-2.7.0.tar.gz",
    "platform": null,
    "description": "===========\nJSON models\n===========\n\n.. image:: https://jazzband.co/static/img/badge.svg\n   :target: https://jazzband.co/\n   :alt: Jazzband\n\n.. image:: https://badge.fury.io/py/jsonmodels.svg\n   :target: http://badge.fury.io/py/jsonmodels\n\n.. image:: https://github.com/jazzband/jsonmodels/workflows/Test/badge.svg\n   :target: https://github.com/jazzband/jsonmodels/actions\n   :alt: Tests\n\n.. image:: https://img.shields.io/pypi/dm/jsonmodels.svg\n   :target: https://pypi.python.org/pypi/jsonmodels\n   :alt: PyPI\n\n.. image:: https://codecov.io/gh/jazzband/jsonmodels/branch/master/graph/badge.svg\n   :target: https://codecov.io/gh/jazzband/jsonmodels\n   :alt: Coverage\n\n`jsonmodels` is library to make it easier for you to deal with structures that\nare converted to, or read from JSON.\n\n* Free software: BSD license\n* Documentation: http://jsonmodels.rtfd.org\n* Source: https://github.com/jazzband/jsonmodels\n\nFeatures\n--------\n\n* Fully tested with Python 3.8+.\n\n* Support for PyPy 3.9 and 3.10 (see implementation notes in docs for more details).\n\n* Create Django-like models:\n\n  .. code-block:: python\n\n    from jsonmodels import models, fields, errors, validators\n\n\n    class Cat(models.Base):\n\n        name = fields.StringField(required=True)\n        breed = fields.StringField()\n        love_humans = fields.IntField(nullable=True)\n\n\n    class Dog(models.Base):\n\n        name = fields.StringField(required=True)\n        age = fields.IntField()\n\n\n    class Car(models.Base):\n\n        registration_number = fields.StringField(required=True)\n        engine_capacity = fields.FloatField()\n        color = fields.StringField()\n\n\n    class Person(models.Base):\n\n        name = fields.StringField(required=True)\n        surname = fields.StringField(required=True)\n        nickname = fields.StringField(nullable=True)\n        car = fields.EmbeddedField(Car)\n        pets = fields.ListField([Cat, Dog], nullable=True)\n\n* Access to values through attributes:\n\n  .. code-block:: python\n\n    >>> cat = Cat()\n    >>> cat.populate(name='Garfield')\n    >>> cat.name\n    'Garfield'\n    >>> cat.breed = 'mongrel'\n    >>> cat.breed\n    'mongrel'\n\n* Validate models:\n\n  .. code-block:: python\n\n    >>> person = Person(name='Chuck', surname='Norris')\n    >>> person.validate()\n    None\n\n    >>> dog = Dog()\n    >>> dog.validate()\n    *** ValidationError: Field \"name\" is required!\n\n* Cast models to python struct and JSON:\n\n  .. code-block:: python\n\n    >>> cat = Cat(name='Garfield')\n    >>> dog = Dog(name='Dogmeat', age=9)\n    >>> car = Car(registration_number='ASDF 777', color='red')\n    >>> person = Person(name='Johny', surname='Bravo', pets=[cat, dog])\n    >>> person.car = car\n    >>> person.to_struct()\n    {\n        'car': {\n            'color': 'red',\n            'registration_number': 'ASDF 777'\n        },\n        'surname': 'Bravo',\n        'name': 'Johny',\n        'nickname': None,\n        'pets': [\n            {'name': 'Garfield'},\n            {'age': 9, 'name': 'Dogmeat'}\n        ]\n    }\n\n    >>> import json\n    >>> person_json = json.dumps(person.to_struct())\n\n* You don't like to write JSON Schema? Let `jsonmodels` do it for you:\n\n  .. code-block:: python\n\n    >>> person = Person()\n    >>> person.to_json_schema()\n    {\n        'additionalProperties': False,\n        'required': ['surname', 'name'],\n        'type': 'object',\n        'properties': {\n            'car': {\n                'additionalProperties': False,\n                'required': ['registration_number'],\n                'type': 'object',\n                'properties': {\n                    'color': {'type': 'string'},\n                    'engine_capacity': {'type': ''},\n                    'registration_number': {'type': 'string'}\n                }\n            },\n            'surname': {'type': 'string'},\n            'name': {'type': 'string'},\n            'nickname': {'type': ['string', 'null']}\n            'pets': {\n                'items': {\n                    'oneOf': [\n                        {\n                            'additionalProperties': False,\n                            'required': ['name'],\n                            'type': 'object',\n                            'properties': {\n                                'breed': {'type': 'string'},\n                                'name': {'type': 'string'}\n                            }\n                        },\n                        {\n                            'additionalProperties': False,\n                            'required': ['name'],\n                            'type': 'object',\n                            'properties': {\n                                'age': {'type': 'number'},\n                                'name': {'type': 'string'}\n                            }\n                        },\n                        {\n                            'type': 'null'\n                        }\n                    ]\n                },\n                'type': 'array'\n            }\n        }\n    }\n\n* Validate models and use validators, that affect generated schema:\n\n  .. code-block:: python\n\n    >>> class Person(models.Base):\n    ...\n    ...     name = fields.StringField(\n    ...         required=True,\n    ...         validators=[\n    ...             validators.Regex('^[A-Za-z]+$'),\n    ...             validators.Length(3, 25),\n    ...         ],\n    ...     )\n    ...     age = fields.IntField(\n    ...         nullable=True,\n    ...         validators=[\n    ...             validators.Min(18),\n    ...             validators.Max(101),\n    ...         ]\n    ...     )\n    ...     nickname = fields.StringField(\n    ...         required=True,\n    ...         nullable=True\n    ...     )\n    ...\n\n    >>> person = Person()\n    >>> person.age = 11\n    >>> person.validate()\n    *** ValidationError: '11' is lower than minimum ('18').\n    >>> person.age = None\n    >>> person.validate()\n    None\n\n    >>> person.age = 19\n    >>> person.name = 'Scott_'\n    >>> person.validate()\n    *** ValidationError: Value \"Scott_\" did not match pattern \"^[A-Za-z]+$\".\n\n    >>> person.name = 'Scott'\n    >>> person.validate()\n    None\n\n    >>> person.nickname = None\n    >>> person.validate()\n    *** ValidationError: Field is required!\n\n    >>> person.to_json_schema()\n    {\n        \"additionalProperties\": false,\n        \"properties\": {\n            \"age\": {\n                \"maximum\": 101,\n                \"minimum\": 18,\n                \"type\": [\"number\", \"null\"]\n            },\n            \"name\": {\n                \"maxLength\": 25,\n                \"minLength\": 3,\n                \"pattern\": \"/^[A-Za-z]+$/\",\n                \"type\": \"string\"\n            },\n            \"nickname\": {,\n                \"type\": [\"string\", \"null\"]\n            }\n        },\n        \"required\": [\n            \"nickname\",\n            \"name\"\n        ],\n        \"type\": \"object\"\n    }\n\n  You can also validate scalars, when needed:\n\n  .. code-block:: python\n\n    >>> class Person(models.Base):\n    ...\n    ...     name = fields.StringField(\n    ...         required=True,\n    ...         validators=[\n    ...             validators.Regex('^[A-Za-z]+$'),\n    ...             validators.Length(3, 25),\n    ...         ],\n    ...     )\n    ...     age = fields.IntField(\n    ...         nullable=True,\n    ...         validators=[\n    ...             validators.Min(18),\n    ...             validators.Max(101),\n    ...         ]\n    ...     )\n    ...     nickname = fields.StringField(\n    ...         required=True,\n    ...         nullable=True\n    ...     )\n    ...\n\n    >>> def only_odd_numbers(item):\n    ... if item % 2 != 1:\n    ...    raise validators.ValidationError(\"Only odd numbers are accepted\")\n    ...\n    >>> class Person(models.Base):\n    ... lucky_numbers = fields.ListField(int, item_validators=[only_odd_numbers])\n    ... item_validator_str = fields.ListField(\n    ...        str,\n    ...        item_validators=[validators.Length(10, 20), validators.Regex(r\"\\w+\")],\n    ...        validators=[validators.Length(1, 2)],\n    ...    )\n    ...\n    >>> Person.to_json_schema()\n    {\n        \"type\": \"object\",\n        \"additionalProperties\": false,\n        \"properties\": {\n            \"item_validator_str\": {\n                \"type\": \"array\",\n                \"items\": {\n                    \"type\": \"string\",\n                    \"minLength\": 10,\n                    \"maxLength\": 20,\n                    \"pattern\": \"/\\\\w+/\"\n                },\n                \"minItems\": 1,\n                \"maxItems\": 2\n            },\n            \"lucky_numbers\": {\n                \"type\": \"array\",\n                \"items\": {\n                    \"type\": \"number\"\n                }\n            }\n        }\n    }\n\n(Note that `only_odd_numbers` did not modify schema, since only class based validators are\nable to do that, though it will still work as expected in python. Use class based validators\nthat can be expressed in json schema if you want to be 100% correct on schema side.)\n\n* Lazy loading, best for circular references:\n\n  .. code-block:: python\n\n    >>> class Primary(models.Base):\n    ...\n    ...     name = fields.StringField()\n    ...     secondary = fields.EmbeddedField('Secondary')\n\n    >>> class Secondary(models.Base):\n    ...\n    ...    data = fields.IntField()\n    ...    first = fields.EmbeddedField('Primary')\n\n  You can use either `Model`, full path `path.to.Model` or relative imports\n  `.Model` or `...Model`.\n\n* Using definitions to generate schema for circular references:\n\n  .. code-block:: python\n\n    >>> class File(models.Base):\n    ...\n    ...     name = fields.StringField()\n    ...     size = fields.FloatField()\n\n    >>> class Directory(models.Base):\n    ...\n    ...     name = fields.StringField()\n    ...     children = fields.ListField(['Directory', File])\n\n    >>> class Filesystem(models.Base):\n    ...\n    ...     name = fields.StringField()\n    ...     children = fields.ListField([Directory, File])\n\n    >>> Filesystem.to_json_schema()\n    {\n        \"type\": \"object\",\n        \"properties\": {\n            \"name\": {\"type\": \"string\"}\n            \"children\": {\n                \"items\": {\n                    \"oneOf\": [\n                        \"#/definitions/directory\",\n                        \"#/definitions/file\"\n                    ]\n                },\n                \"type\": \"array\"\n            }\n        },\n        \"additionalProperties\": false,\n        \"definitions\": {\n            \"directory\": {\n                \"additionalProperties\": false,\n                \"properties\": {\n                    \"children\": {\n                        \"items\": {\n                            \"oneOf\": [\n                                \"#/definitions/directory\",\n                                \"#/definitions/file\"\n                            ]\n                        },\n                        \"type\": \"array\"\n                    },\n                    \"name\": {\"type\": \"string\"}\n                },\n                \"type\": \"object\"\n            },\n            \"file\": {\n                \"additionalProperties\": false,\n                \"properties\": {\n                    \"name\": {\"type\": \"string\"},\n                    \"size\": {\"type\": \"number\"}\n                },\n                \"type\": \"object\"\n            }\n        }\n    }\n\n* Dealing with schemaless data\n\n(Plese note that using schemaless fields can cause your models to get out of control - especially if\nyou are the one responsible for data schema. On the other hand there is usually the case when incomming\ndata are with no schema defined and schemaless fields are the way to go.)\n\n  .. code-block:: python\n\n    >>> class Event(models.Base):\n    ...\n    ...     name = fields.StringField()\n    ...     size = fields.FloatField()\n    ...     extra = fields.DictField()\n\n    >>> Event.to_json_schema()\n    {\n        \"type\": \"object\",\n        \"additionalProperties\": false,\n        \"properties\": {\n            \"extra\": {\n                \"type\": \"object\"\n            },\n            \"name\": {\n                \"type\": \"string\"\n            },\n            \"size\": {\n                \"type\": \"float\"\n            }\n        }\n    }\n\n`DictField` allow to pass any dict of values (`\"type\": \"object\"`), but note, that it will not make any validation\non values except for the dict type.\n\n* Compare JSON schemas:\n\n  .. code-block:: python\n\n    >>> from jsonmodels.utils import compare_schemas\n    >>> schema1 = {'type': 'object'}\n    >>> schema2 = {'type': 'array'}\n    >>> compare_schemas(schema1, schema1)\n    True\n    >>> compare_schemas(schema1, schema2)\n    False\n\nMore\n----\n\nFor more examples and better description see full documentation:\nhttp://jsonmodels.rtfd.org.\n\n\n\n\nHistory\n-------\n\n2.7.0 (2023-12-17)\n++++++++++++++++++\n\n* Added Python 3.12, PyPy 3.9 and 3.10 support.\n* Removed Python 3.7 and PyPy 3.8 support.\n\n2.6.0 (2022-10-14)\n++++++++++++++++++\n\n* Removed Python 3.6 support.\n* Added support for Python 3.11.\n\n2.5.1 (2022-06-16)\n++++++++++++++++++\n\n* Specified PyPy version to PyPy 3.8.\n* Added support for Python 3.10.\n\n2.5.0 (2021-07-26)\n++++++++++++++++++\n\n* Improvied error messages for field validation errors.\n* Allowed to validate non model list items.\n* Added DictField.\n\n2.4.1 (2021-02-19)\n++++++++++++++++++\n\n* Added Python 3.8 and 3.9 support.\n* Removed Python 2.7, 3.3 and 3.5 support.\n\n2.4 (2018-12-01)\n++++++++++++++++\n\n* Fixed length validator.\n* Added Python 3.7 support.\n\n2.3 (2018-02-04)\n++++++++++++++++\n\n* Added name mapping for fields.\n* Added value parsing to IntField.\n* Fixed bug with ECMA regex flags recognition.\n\n2.2 (2017-08-21)\n++++++++++++++++\n\n* Fixed time fields, when value is not required.\n* Dropped support for python 2.6\n* Added support for python 3.6\n* Added nullable param for fields.\n* Improved model representation.\n\n2.1.5 (2017-02-01)\n++++++++++++++++++\n\n* Fixed DateTimefield error when value is None.\n* Fixed comparing models without required values.\n\n2.1.4 (2017-01-24)\n++++++++++++++++++\n\n* Allow to compare models based on their type and fields (rather than their\n  reference).\n\n2.1.3 (2017-01-16)\n++++++++++++++++++\n\n* Fixed generated schema.\n* Improved JSON serialization.\n\n2.1.2 (2016-01-06)\n++++++++++++++++++\n\n* Fixed memory leak.\n\n2.1.1 (2015-11-15)\n++++++++++++++++++\n\n* Added support for Python 2.6, 3.2 and 3.5.\n\n2.1 (2015-11-02)\n++++++++++++++++\n\n* Added lazy loading of types.\n* Added schema generation for circular models.\n* Improved readability of validation error.\n* Fixed structure generation for list field.\n\n2.0.1 (2014-11-15)\n++++++++++++++++++\n\n* Fixed schema generation for primitives.\n\n2.0 (2014-11-14)\n++++++++++++++++\n\n* Fields now are descriptors.\n* Empty required fields are still validated only during explicite validations.\n\nBackward compatibility breaks\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n* Renamed _types to types in fields.\n* Renamed _items_types to items_types in ListField.\n* Removed data transformers.\n* Renamed module `error` to `errors`.\n* Removed explicit validation - validation occurs at assign time.\n* Renamed `get_value_replacement` to `get_default_value`.\n* Renamed modules `utils` to `utilities`.\n\n1.4 (2014-07-22)\n++++++++++++++++\n\n* Allowed validators to modify generated schema.\n* Added validator for maximum value.\n* Added utilities to convert regular expressions between Python and ECMA\n  formats.\n* Added validator for regex.\n* Added validator for minimum value.\n* By default \"validators\" property of field is an empty list.\n\n1.3.1 (2014-07-13)\n++++++++++++++++++\n\n* Fixed generation of schema for BoolField.\n\n1.3 (2014-07-13)\n++++++++++++++++\n\n* Added new fields (BoolField, TimeField, DateField and DateTimeField).\n* ListField is always not required.\n* Schema can be now generated from class itself (not from an instance).\n\n1.2 (2014-06-18)\n++++++++++++++++\n\n* Fixed values population, when value is not dictionary.\n* Added custom validators.\n* Added tool for schema comparison.\n\n1.1.1 (2014-06-07)\n++++++++++++++++++\n\n* Added possibility to populate already initialized data to EmbeddedField.\n* Added `compare_schemas` utility.\n\n1.1 (2014-05-19)\n++++++++++++++++\n\n* Added docs.\n* Added json schema generation.\n* Added tests for PEP8 and complexity.\n* Moved to Python 3.4.\n* Added PEP257 compatibility.\n* Added help text to fields.\n\n1.0.5 (2014-04-14)\n++++++++++++++++++\n\n* Added data transformers.\n\n1.0.4 (2014-04-13)\n++++++++++++++++++\n\n* List field now supports simple types.\n\n1.0.3 (2014-04-10)\n++++++++++++++++++\n\n* Fixed compatibility with Python 3.\n* Fixed `str` and `repr` methods.\n\n1.0.2 (2014-04-03)\n++++++++++++++++++\n\n* Added deep data initialization.\n\n1.0.1 (2014-04-03)\n++++++++++++++++++\n\n* Added `populate` method.\n\n1.0 (2014-04-02)\n++++++++++++++++\n\n* First stable release on PyPI.\n\n0.1.0 (2014-03-17)\n++++++++++++++++++\n\n* First release on PyPI.\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Models to make easier to deal with structures that are converted to, or read from JSON.",
    "version": "2.7.0",
    "project_urls": {
        "Homepage": "https://github.com/jazzband/jsonmodels"
    },
    "split_keywords": [
        "jsonmodels"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d3198d1496e5ca6d41d02dd16d6024c3cc38a6bc9343217f41ec4f261fd904fd",
                "md5": "41d3b650d4fd223880ea3fac2ac33c1a",
                "sha256": "6799639f40978d27f93ba4d1a5c9a5cb54a9c63937de4e81cd0d741e32bcec9f"
            },
            "downloads": -1,
            "filename": "jsonmodels-2.7.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "41d3b650d4fd223880ea3fac2ac33c1a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18217,
            "upload_time": "2023-12-17T13:28:06",
            "upload_time_iso_8601": "2023-12-17T13:28:06.494979Z",
            "url": "https://files.pythonhosted.org/packages/d3/19/8d1496e5ca6d41d02dd16d6024c3cc38a6bc9343217f41ec4f261fd904fd/jsonmodels-2.7.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fef777d39f85afc8928e66737ad2ca754a2539a8202abafb5079fc36e1875bc4",
                "md5": "6c48bf0736333cff9eb61095ecc9dc2e",
                "sha256": "8c019bf1bd252ac3e401127507d735ea0fd6ce30921802b5fc5c761cd41a18bb"
            },
            "downloads": -1,
            "filename": "jsonmodels-2.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6c48bf0736333cff9eb61095ecc9dc2e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 33194,
            "upload_time": "2023-12-17T13:29:14",
            "upload_time_iso_8601": "2023-12-17T13:29:14.172102Z",
            "url": "https://files.pythonhosted.org/packages/fe/f7/77d39f85afc8928e66737ad2ca754a2539a8202abafb5079fc36e1875bc4/jsonmodels-2.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-17 13:29:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jazzband",
    "github_project": "jsonmodels",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "jsonmodels"
}
        
Elapsed time: 0.16817s