isjsonschemasubset


Nameisjsonschemasubset JSON
Version 0.0.1 PyPI version JSON
download
home_page
SummaryCheck one JSON schema is a subset of another
upload_time2023-09-20 16:48:23
maintainer
docs_urlNone
author
requires_python>=3.11
licenseMIT License Copyright (c) 2023 Oliver Russell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords jsonschema pydantic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # `isjsonschemasubset`

Check one JSON schema is a subset of another. Plays nicely with `Pydantic`.

```python
from pathlib import Path
from isjsonschemasubset import dump, issubset, load

path_to_a = Path(__file__).parent / "a.json"
path_to_b = Path(__file__).parent / "b.json"
dump(A, path_to_a)  # where A is a `type[pydantic.BaseModel]`
dump(B, path_to_b)  # where B is a `type[pydantic.BaseModel]`
json_schema_a = load(path_to_a)
json_schema_b = load(path_to_b)

for error in issubset(json_schema_a, json_schema_b):
    ...
```

Yields errors if type `A` is not a subset of `B`.

In this context, "is a subset of" means that if we were to do:

```python
B(**a.model_dump(mode="json"))
```

We would _not_ get an error. This is very important when deserializing data from JSON columns in the database and for writing backwards compatible APIs.

See [tests/test_schema_versions.py](tests/test_schema_versions.py) for further xample usage. In this case, every time we change `Foo` (or anything that `Foo` refers to recursively), we dump a new schema in [tests/schemas/Foo](tests/schemas/Foo) and check all of the schemas are backwards compatible.

# Install

```bash
pip install isjsonschemasubset
```

## Dev install

```bash
git clone git@github.com:leontrolski/isjsonschemasubset.git
pip install -r requirements-dev.txt
pytest
mypy src tests --strict
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "isjsonschemasubset",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "Oliver Russell <ojhrussell@gmail.com>",
    "keywords": "JSONSchema,pydantic",
    "author": "",
    "author_email": "Oliver Russell <ojhrussell@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/b9/32/91d545369bc440085a772ec80e40e000e49d27af37f6ae1ae4fd6bfc36aa/isjsonschemasubset-0.0.1.tar.gz",
    "platform": null,
    "description": "# `isjsonschemasubset`\n\nCheck one JSON schema is a subset of another. Plays nicely with `Pydantic`.\n\n```python\nfrom pathlib import Path\nfrom isjsonschemasubset import dump, issubset, load\n\npath_to_a = Path(__file__).parent / \"a.json\"\npath_to_b = Path(__file__).parent / \"b.json\"\ndump(A, path_to_a)  # where A is a `type[pydantic.BaseModel]`\ndump(B, path_to_b)  # where B is a `type[pydantic.BaseModel]`\njson_schema_a = load(path_to_a)\njson_schema_b = load(path_to_b)\n\nfor error in issubset(json_schema_a, json_schema_b):\n    ...\n```\n\nYields errors if type `A` is not a subset of `B`.\n\nIn this context, \"is a subset of\" means that if we were to do:\n\n```python\nB(**a.model_dump(mode=\"json\"))\n```\n\nWe would _not_ get an error. This is very important when deserializing data from JSON columns in the database and for writing backwards compatible APIs.\n\nSee [tests/test_schema_versions.py](tests/test_schema_versions.py) for further xample usage. In this case, every time we change `Foo` (or anything that `Foo` refers to recursively), we dump a new schema in [tests/schemas/Foo](tests/schemas/Foo) and check all of the schemas are backwards compatible.\n\n# Install\n\n```bash\npip install isjsonschemasubset\n```\n\n## Dev install\n\n```bash\ngit clone git@github.com:leontrolski/isjsonschemasubset.git\npip install -r requirements-dev.txt\npytest\nmypy src tests --strict\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Oliver Russell  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Check one JSON schema is a subset of another",
    "version": "0.0.1",
    "project_urls": {
        "homepage": "https://leontrolski.github.io/"
    },
    "split_keywords": [
        "jsonschema",
        "pydantic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3e6ae35b70a2597d304231dddfe2f26fb636a254761362045508ab42944d1682",
                "md5": "c44446a0c3b8b11f2a42c8057c464f16",
                "sha256": "91e203b901d994e7216842f4683765cbaefee8ed716f37b6fd337144826006ab"
            },
            "downloads": -1,
            "filename": "isjsonschemasubset-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c44446a0c3b8b11f2a42c8057c464f16",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 5639,
            "upload_time": "2023-09-20T16:48:21",
            "upload_time_iso_8601": "2023-09-20T16:48:21.606835Z",
            "url": "https://files.pythonhosted.org/packages/3e/6a/e35b70a2597d304231dddfe2f26fb636a254761362045508ab42944d1682/isjsonschemasubset-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b93291d545369bc440085a772ec80e40e000e49d27af37f6ae1ae4fd6bfc36aa",
                "md5": "2054dd44a6b2c883e0c142a0aeddbeeb",
                "sha256": "526085a913f0d519363311d857377028b41d8ed3514c5539cc8df3a618a1eb8a"
            },
            "downloads": -1,
            "filename": "isjsonschemasubset-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2054dd44a6b2c883e0c142a0aeddbeeb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 6174,
            "upload_time": "2023-09-20T16:48:23",
            "upload_time_iso_8601": "2023-09-20T16:48:23.161584Z",
            "url": "https://files.pythonhosted.org/packages/b9/32/91d545369bc440085a772ec80e40e000e49d27af37f6ae1ae4fd6bfc36aa/isjsonschemasubset-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-20 16:48:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "isjsonschemasubset"
}
        
Elapsed time: 0.12375s