deep-sorted


Namedeep-sorted JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/danhje/deep-sorted
SummarySorting of nested dicts and lists
upload_time2023-03-16 20:36:14
maintainer
docs_urlNone
authorDaniel Hjertholm
requires_python>=3.8.1,<4.0
licenseMIT
keywords sort sorted nested recursive deep dict list
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # deep-sorted

![Testing and linting](https://github.com/danhje/deep-sorted/workflows/Test%20And%20Lint/badge.svg)
[![codecov](https://codecov.io/gh/danhje/deep-sorted/branch/master/graph/badge.svg)](https://codecov.io/gh/danhje/deep-sorted)
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/danhje/deep-sorted?include_prereleases)
![PyPI](https://img.shields.io/pypi/v/deep-sorted)

## Motivation

When validating parsed JSON objects, schemas and other nested data structures in unit tests, order
is typically not important. And yet I often find myself manually sorting the target structures
when the internals of the tested function is modified such that order is changed. With this package,
both the target and the actual structure can be recursively sorted before comparison.

## Installation

Using poetry:

```shell
poetry add deep-sorted
```

Using pipenv:

```shell
pipenv install deep-sorted
```

Using pip:

```shell
pip install deep-sorted
```

## Usage

```python
from deep_sorted import deep_sorted
from datetime import datetime

one = {
    "id": 9,
    "name": "Ted Chiang",
    "books": [
        {
            "id": 124,
            "published": datetime(1991, 8, 1, 0, 0),
            "title": "Understand",
            "ratings": (6, 6, 3, 5, 6, 6, 0, 6, 0),
        },
        {
            "id": 125,
            "published": datetime(2019, 5, 7, 0, 0),
            "title": "Exhalation",
        },
    ],
}

two = {
    "books": [
        {
            "published": datetime(2019, 5, 7, 0, 0),
            "title": "Exhalation",
            "id": 125,
        },
        {
            "ratings": (3, 0, 0, 6, 6, 6, 6, 5, 6),
            "id": 124,
            "published": datetime(1991, 8, 1, 0, 0),
            "title": "Understand",
        },
    ],
    "id": 9,
    "name": "Ted Chiang",
}

assert deep_sorted(one) == deep_sorted(two)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/danhje/deep-sorted",
    "name": "deep-sorted",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.1,<4.0",
    "maintainer_email": "",
    "keywords": "sort,sorted,nested,recursive,deep,dict,list",
    "author": "Daniel Hjertholm",
    "author_email": "daniel.hjertholm@icloud.com",
    "download_url": "https://files.pythonhosted.org/packages/33/d1/f3a50a8bd083e2c0d077065763c18197f322706f21f2e5832ce6f05da1bd/deep_sorted-0.0.3.tar.gz",
    "platform": null,
    "description": "# deep-sorted\n\n![Testing and linting](https://github.com/danhje/deep-sorted/workflows/Test%20And%20Lint/badge.svg)\n[![codecov](https://codecov.io/gh/danhje/deep-sorted/branch/master/graph/badge.svg)](https://codecov.io/gh/danhje/deep-sorted)\n![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/danhje/deep-sorted?include_prereleases)\n![PyPI](https://img.shields.io/pypi/v/deep-sorted)\n\n## Motivation\n\nWhen validating parsed JSON objects, schemas and other nested data structures in unit tests, order\nis typically not important. And yet I often find myself manually sorting the target structures\nwhen the internals of the tested function is modified such that order is changed. With this package,\nboth the target and the actual structure can be recursively sorted before comparison.\n\n## Installation\n\nUsing poetry:\n\n```shell\npoetry add deep-sorted\n```\n\nUsing pipenv:\n\n```shell\npipenv install deep-sorted\n```\n\nUsing pip:\n\n```shell\npip install deep-sorted\n```\n\n## Usage\n\n```python\nfrom deep_sorted import deep_sorted\nfrom datetime import datetime\n\none = {\n    \"id\": 9,\n    \"name\": \"Ted Chiang\",\n    \"books\": [\n        {\n            \"id\": 124,\n            \"published\": datetime(1991, 8, 1, 0, 0),\n            \"title\": \"Understand\",\n            \"ratings\": (6, 6, 3, 5, 6, 6, 0, 6, 0),\n        },\n        {\n            \"id\": 125,\n            \"published\": datetime(2019, 5, 7, 0, 0),\n            \"title\": \"Exhalation\",\n        },\n    ],\n}\n\ntwo = {\n    \"books\": [\n        {\n            \"published\": datetime(2019, 5, 7, 0, 0),\n            \"title\": \"Exhalation\",\n            \"id\": 125,\n        },\n        {\n            \"ratings\": (3, 0, 0, 6, 6, 6, 6, 5, 6),\n            \"id\": 124,\n            \"published\": datetime(1991, 8, 1, 0, 0),\n            \"title\": \"Understand\",\n        },\n    ],\n    \"id\": 9,\n    \"name\": \"Ted Chiang\",\n}\n\nassert deep_sorted(one) == deep_sorted(two)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Sorting of nested dicts and lists",
    "version": "0.0.3",
    "split_keywords": [
        "sort",
        "sorted",
        "nested",
        "recursive",
        "deep",
        "dict",
        "list"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5d4b83b0d3e8f9bf8590dd2522e8fd5e8102b851e16d383841ca848a2232f9bc",
                "md5": "4bc9d2fce8a034061fc0479a42dca34f",
                "sha256": "a9058f3fcd5d004a29a472271ee41c2d5168063105d5943c18430b4886263a4c"
            },
            "downloads": -1,
            "filename": "deep_sorted-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4bc9d2fce8a034061fc0479a42dca34f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.1,<4.0",
            "size": 3380,
            "upload_time": "2023-03-16T20:36:12",
            "upload_time_iso_8601": "2023-03-16T20:36:12.469469Z",
            "url": "https://files.pythonhosted.org/packages/5d/4b/83b0d3e8f9bf8590dd2522e8fd5e8102b851e16d383841ca848a2232f9bc/deep_sorted-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33d1f3a50a8bd083e2c0d077065763c18197f322706f21f2e5832ce6f05da1bd",
                "md5": "f47e4bac9a9e5dfcf05fd53f1f4b63e1",
                "sha256": "c962117596b7969e992664c673f7c5e300493b16d59f1b75f834e0f5fc1752bb"
            },
            "downloads": -1,
            "filename": "deep_sorted-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "f47e4bac9a9e5dfcf05fd53f1f4b63e1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.1,<4.0",
            "size": 2690,
            "upload_time": "2023-03-16T20:36:14",
            "upload_time_iso_8601": "2023-03-16T20:36:14.500760Z",
            "url": "https://files.pythonhosted.org/packages/33/d1/f3a50a8bd083e2c0d077065763c18197f322706f21f2e5832ce6f05da1bd/deep_sorted-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-16 20:36:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "danhje",
    "github_project": "deep-sorted",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "deep-sorted"
}
        
Elapsed time: 1.04969s