json-numpy


Namejson-numpy JSON
Version 2.0.0 PyPI version JSON
download
home_page
SummaryJSON encoding/decoding for Numpy arrays and scalars
upload_time2024-02-04 14:06:02
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT License Copyright (c) 2024 Crimson-Crow <github@crimsoncrow.dev> 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 json numpy serialization encode decode encoding decoding
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            json-numpy
==========

[![PyPI](https://img.shields.io/pypi/v/json-numpy)](https://pypi.org/project/json-numpy/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/json-numpy)](https://pypi.org/project/json-numpy/)
[![GitHub](https://img.shields.io/github/license/Crimson-Crow/json-numpy)]((https://github.com/Crimson-Crow/json-numpy/blob/main/LICENSE.txt))

Description
-----------

`json-numpy` provides lossless and quick JSON encoding/decoding for [`numpy`](http://www.numpy.org/) arrays and scalars.

Installation
------------

`json-numpy` can be installed using [`pip`](https://pip.pypa.io/en/stable/):

    $ pip install json-numpy

Usage
-----

For a quick start, `json_numpy` can be used as a simple drop-in replacement of the built-in `json` module. \
The `dump()`, `load()`, `dumps()` and `loads()` methods are implemented by wrapping the original methods and replacing the default encoder and decoder. \
More information on the usage can be found in the `json` module's [documentation](https://docs.python.org/3/library/json.html).

```python
import numpy as np
import json_numpy

arr = np.array([0, 1, 2])
encoded_arr_str = json_numpy.dumps(arr)
decoded_arr = json_numpy.loads(encoded_arr_str)
```

Another way of using `json_numpy` is to explicitly use the provided encoder and decoder functions in conjunction with the `json` module.

```python
import json
import numpy as np
from json_numpy import default, object_hook

arr = np.array([0, 1, 2])
encoded_arr_str = json.dumps(arr, default=default)
decoded_arr = json.loads(encoded_arr_str, object_hook=object_hook)
```

Finally, the last way of using `json_numpy` is by monkey patching the `json` module after importing it first:

```python
import json
import numpy as np
import json_numpy

json_numpy.patch()

arr = np.array([0, 1, 2])
encoded_arr_str = json.dumps(arr)
decoded_arr = json.loads(encoded_arr_str)
```

This method can be used to change the behavior of a module depending on the `json` module without editing its code.

Tests
-----

The simplest way to run tests is:

    $ python -m unittest

As a more robust alternative, you can install [`tox`](https://tox.readthedocs.io/en/latest/install.html) to automatically test across the supported python versions, then run:

    $ tox

Issue tracker
-------------

Please report any bugs or enhancement ideas using the [issue tracker](https://github.com/Crimson-Crow/json-numpy/issues).

License
-------

`json-numpy` is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT) (see [LICENSE.txt](https://github.com/Crimson-Crow/json-numpy/blob/main/LICENSE.txt) for more information).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "json-numpy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Crimson-Crow <github@crimsoncrow.dev>",
    "keywords": "json,numpy,serialization,encode,decode,encoding,decoding",
    "author": "",
    "author_email": "Crimson-Crow <github@crimsoncrow.dev>",
    "download_url": "https://files.pythonhosted.org/packages/b3/e7/7c7c1775c1feddd142b5910b23d6e70615c422325eec6f4a23fdc115dd2e/json-numpy-2.0.0.tar.gz",
    "platform": null,
    "description": "json-numpy\r\n==========\r\n\r\n[![PyPI](https://img.shields.io/pypi/v/json-numpy)](https://pypi.org/project/json-numpy/)\r\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/json-numpy)](https://pypi.org/project/json-numpy/)\r\n[![GitHub](https://img.shields.io/github/license/Crimson-Crow/json-numpy)]((https://github.com/Crimson-Crow/json-numpy/blob/main/LICENSE.txt))\r\n\r\nDescription\r\n-----------\r\n\r\n`json-numpy` provides lossless and quick JSON encoding/decoding for [`numpy`](http://www.numpy.org/) arrays and scalars.\r\n\r\nInstallation\r\n------------\r\n\r\n`json-numpy` can be installed using [`pip`](https://pip.pypa.io/en/stable/):\r\n\r\n    $ pip install json-numpy\r\n\r\nUsage\r\n-----\r\n\r\nFor a quick start, `json_numpy` can be used as a simple drop-in replacement of the built-in `json` module. \\\r\nThe `dump()`, `load()`, `dumps()` and `loads()` methods are implemented by wrapping the original methods and replacing the default encoder and decoder. \\\r\nMore information on the usage can be found in the `json` module's [documentation](https://docs.python.org/3/library/json.html).\r\n\r\n```python\r\nimport numpy as np\r\nimport json_numpy\r\n\r\narr = np.array([0, 1, 2])\r\nencoded_arr_str = json_numpy.dumps(arr)\r\ndecoded_arr = json_numpy.loads(encoded_arr_str)\r\n```\r\n\r\nAnother way of using `json_numpy` is to explicitly use the provided encoder and decoder functions in conjunction with the `json` module.\r\n\r\n```python\r\nimport json\r\nimport numpy as np\r\nfrom json_numpy import default, object_hook\r\n\r\narr = np.array([0, 1, 2])\r\nencoded_arr_str = json.dumps(arr, default=default)\r\ndecoded_arr = json.loads(encoded_arr_str, object_hook=object_hook)\r\n```\r\n\r\nFinally, the last way of using `json_numpy` is by monkey patching the `json` module after importing it first:\r\n\r\n```python\r\nimport json\r\nimport numpy as np\r\nimport json_numpy\r\n\r\njson_numpy.patch()\r\n\r\narr = np.array([0, 1, 2])\r\nencoded_arr_str = json.dumps(arr)\r\ndecoded_arr = json.loads(encoded_arr_str)\r\n```\r\n\r\nThis method can be used to change the behavior of a module depending on the `json` module without editing its code.\r\n\r\nTests\r\n-----\r\n\r\nThe simplest way to run tests is:\r\n\r\n    $ python -m unittest\r\n\r\nAs a more robust alternative, you can install [`tox`](https://tox.readthedocs.io/en/latest/install.html) to automatically test across the supported python versions, then run:\r\n\r\n    $ tox\r\n\r\nIssue tracker\r\n-------------\r\n\r\nPlease report any bugs or enhancement ideas using the [issue tracker](https://github.com/Crimson-Crow/json-numpy/issues).\r\n\r\nLicense\r\n-------\r\n\r\n`json-numpy` is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT) (see [LICENSE.txt](https://github.com/Crimson-Crow/json-numpy/blob/main/LICENSE.txt) for more information).\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Crimson-Crow <github@crimsoncrow.dev>  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": "JSON encoding/decoding for Numpy arrays and scalars",
    "version": "2.0.0",
    "project_urls": {
        "Homepage": "https://github.com/Crimson-Crow/json-numpy",
        "Issues": "https://github.com/Crimson-Crow/json-numpy/issues",
        "Repository": "https://github.com/Crimson-Crow/json-numpy.git"
    },
    "split_keywords": [
        "json",
        "numpy",
        "serialization",
        "encode",
        "decode",
        "encoding",
        "decoding"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "da299d66d9620204619ef13bd65ee2f484bdddbca19081dd169e8ea3b343ce5e",
                "md5": "7b1d841d7ef3ae98f2ae0d2985edf478",
                "sha256": "8b4d3a9e8cb54724f94f38eaf2609df1878fc48c32e15fa62e91755b70bc23d0"
            },
            "downloads": -1,
            "filename": "json_numpy-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7b1d841d7ef3ae98f2ae0d2985edf478",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4715,
            "upload_time": "2024-02-04T14:06:00",
            "upload_time_iso_8601": "2024-02-04T14:06:00.823634Z",
            "url": "https://files.pythonhosted.org/packages/da/29/9d66d9620204619ef13bd65ee2f484bdddbca19081dd169e8ea3b343ce5e/json_numpy-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b3e77c7c1775c1feddd142b5910b23d6e70615c422325eec6f4a23fdc115dd2e",
                "md5": "45be2e9eff4e996cb2594346ed4d3427",
                "sha256": "354103f3c3b85490f9328de06305d6e6fd9021bdb2946d73ed5c240e7d233279"
            },
            "downloads": -1,
            "filename": "json-numpy-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "45be2e9eff4e996cb2594346ed4d3427",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 8148,
            "upload_time": "2024-02-04T14:06:02",
            "upload_time_iso_8601": "2024-02-04T14:06:02.977915Z",
            "url": "https://files.pythonhosted.org/packages/b3/e7/7c7c1775c1feddd142b5910b23d6e70615c422325eec6f4a23fdc115dd2e/json-numpy-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-04 14:06:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Crimson-Crow",
    "github_project": "json-numpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "json-numpy"
}
        
Elapsed time: 0.18967s