jsonpickle


Namejsonpickle JSON
Version 4.0.0 PyPI version JSON
download
home_pageNone
Summaryjsonpickle encodes/decodes any Python object to/from JSON
upload_time2024-11-12 04:13:38
maintainerNone
docs_urlNone
authorTheelx
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            .. image:: https://img.shields.io/pypi/v/jsonpickle.svg
   :target: `PyPI link`_

.. image:: https://img.shields.io/pypi/pyversions/jsonpickle.svg
   :target: `PyPI link`_

.. _PyPI link: https://pypi.org/project/jsonpickle

.. image:: https://readthedocs.org/projects/jsonpickle/badge/?version=latest
   :target: https://jsonpickle.readthedocs.io/en/latest/?badge=latest

.. image:: https://github.com/jsonpickle/jsonpickle/actions/workflows/test.yml/badge.svg
   :target: https://github.com/jsonpickle/jsonpickle/actions
   :alt: Github Actions

.. image:: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg
   :target: https://github.com/jsonpickle/jsonpickle/blob/main/COPYING
   :alt: BSD


jsonpickle
==========

jsonpickle is a library for the two-way conversion of complex Python objects
and `JSON <http://json.org/>`_.  jsonpickle builds upon existing JSON
encoders, such as simplejson, json, and ujson.

.. warning::

   jsonpickle can execute arbitrary Python code.

   Please see the Security section for more details.


For complete documentation, please visit the
`jsonpickle documentation <http://jsonpickle.readthedocs.io/>`_.

Bug reports and merge requests are encouraged at the
`jsonpickle repository on github <https://github.com/jsonpickle/jsonpickle>`_.

Usage
=====
The following is a very simple example of how one can use jsonpickle in their scripts/projects. Note the usage of jsonpickle.encode and decode, and how the data is written/encoded to a file and then read/decoded from the file.

.. code-block:: python

    import jsonpickle
    from dataclasses import dataclass
   
    @dataclass
    class Example:
        data: str
   
   
    ex = Example("value1")
    encoded_instance = jsonpickle.encode(ex)
    assert encoded_instance == '{"py/object": "__main__.Example", "data": "value1"}'
   
    with open("example.json", "w+") as f:
        f.write(encoded_instance)
   
    with open("example.json", "r+") as f:
        written_instance = f.read()
        decoded_instance = jsonpickle.decode(written_instance)
    assert decoded_instance == ex

For more examples, see the `examples directory on GitHub <https://github.com/jsonpickle/jsonpickle/tree/main/examples>`_ for example scripts. These can be run on your local machine to see how jsonpickle works and behaves, and how to use it. Contributions from users regarding how they use jsonpickle are welcome!


Why jsonpickle?
===============

Data serialized with python's pickle (or cPickle or dill) is not easily readable outside of python. Using the json format, jsonpickle allows simple data types to be stored in a human-readable format, and more complex data types such as numpy arrays and pandas dataframes, to be machine-readable on any platform that supports json. E.g., unlike pickled data, jsonpickled data stored in an Amazon S3 bucket is indexible by Amazon's Athena.

Security
========

jsonpickle should be treated the same as the
`Python stdlib pickle module <https://docs.python.org/3/library/pickle.html>`_
from a security perspective.

.. warning::

   The jsonpickle module **is not secure**.  Only unpickle data you trust.

   It is possible to construct malicious pickle data which will **execute
   arbitrary code during unpickling**.  Never unpickle data that could have come
   from an untrusted source, or that could have been tampered with.

   Consider signing data with an HMAC if you need to ensure that it has not
   been tampered with.

   Safer deserialization approaches, such as reading JSON directly,
   may be more appropriate if you are processing untrusted data.


Install
=======

Install from pip for the latest stable release:

::

    pip install jsonpickle

Install from github for the latest changes:

::

    pip install git+https://github.com/jsonpickle/jsonpickle.git


Numpy/Pandas Support
====================

jsonpickle includes built-in numpy and pandas extensions.  If you would
like to encode sklearn models, numpy arrays, pandas DataFrames, and other
numpy/pandas-based data, then you must enable the numpy and/or pandas
extensions by registering their handlers::

    >>> import jsonpickle.ext.numpy as jsonpickle_numpy
    >>> import jsonpickle.ext.pandas as jsonpickle_pandas
    >>> jsonpickle_numpy.register_handlers()
    >>> jsonpickle_pandas.register_handlers()


Development
===========

Use `make` to run the unit tests::

        make test

`pytest` is used to run unit tests internally.

A `tox` target is provided to run tests using all installed and supported Python versions::

        make tox

`jsonpickle` itself has no dependencies beyond the Python stdlib.
`tox` is required for testing when using the `tox` test runner only.

The testing requirements are specified in `setup.cfg`.
It is recommended to create a virtualenv and run tests from within the
virtualenv.::

        python3 -mvenv env3
        source env3/bin/activate
        pip install --editable '.[dev]'
        make test

You can also use a tool such as `vx <https://github.com/davvid/vx/>`_
to activate the virtualenv without polluting your shell environment::

        python3 -mvenv env3
        vx env3 pip install --editable '.[dev]'
        vx env3 make test

If you can't use a venv, you can install the testing packages as follows::

        pip install .[testing]

`jsonpickle` supports multiple Python versions, so using a combination of
multiple virtualenvs and `tox` is useful in order to catch compatibility
issues when developing.

GPG Signing
===========

Unfortunately, while versions of jsonpickle before 3.0.1 should still be signed, GPG signing support was removed from PyPi (https://blog.pypi.org/posts/2023-05-23-removing-pgp/) back in May 2023.

License
=======

Licensed under the BSD License. See COPYING for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "jsonpickle",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Theelx",
    "author_email": "David Aguilar <davvid+jsonpickle@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/04/b7/9fb3cb5915f7363ceea7eb433866a69e8c01b43201daf368afd5c2ff722b/jsonpickle-4.0.0.tar.gz",
    "platform": null,
    "description": ".. image:: https://img.shields.io/pypi/v/jsonpickle.svg\n   :target: `PyPI link`_\n\n.. image:: https://img.shields.io/pypi/pyversions/jsonpickle.svg\n   :target: `PyPI link`_\n\n.. _PyPI link: https://pypi.org/project/jsonpickle\n\n.. image:: https://readthedocs.org/projects/jsonpickle/badge/?version=latest\n   :target: https://jsonpickle.readthedocs.io/en/latest/?badge=latest\n\n.. image:: https://github.com/jsonpickle/jsonpickle/actions/workflows/test.yml/badge.svg\n   :target: https://github.com/jsonpickle/jsonpickle/actions\n   :alt: Github Actions\n\n.. image:: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg\n   :target: https://github.com/jsonpickle/jsonpickle/blob/main/COPYING\n   :alt: BSD\n\n\njsonpickle\n==========\n\njsonpickle is a library for the two-way conversion of complex Python objects\nand `JSON <http://json.org/>`_.  jsonpickle builds upon existing JSON\nencoders, such as simplejson, json, and ujson.\n\n.. warning::\n\n   jsonpickle can execute arbitrary Python code.\n\n   Please see the Security section for more details.\n\n\nFor complete documentation, please visit the\n`jsonpickle documentation <http://jsonpickle.readthedocs.io/>`_.\n\nBug reports and merge requests are encouraged at the\n`jsonpickle repository on github <https://github.com/jsonpickle/jsonpickle>`_.\n\nUsage\n=====\nThe following is a very simple example of how one can use jsonpickle in their scripts/projects. Note the usage of jsonpickle.encode and decode, and how the data is written/encoded to a file and then read/decoded from the file.\n\n.. code-block:: python\n\n    import jsonpickle\n    from dataclasses import dataclass\n   \n    @dataclass\n    class Example:\n        data: str\n   \n   \n    ex = Example(\"value1\")\n    encoded_instance = jsonpickle.encode(ex)\n    assert encoded_instance == '{\"py/object\": \"__main__.Example\", \"data\": \"value1\"}'\n   \n    with open(\"example.json\", \"w+\") as f:\n        f.write(encoded_instance)\n   \n    with open(\"example.json\", \"r+\") as f:\n        written_instance = f.read()\n        decoded_instance = jsonpickle.decode(written_instance)\n    assert decoded_instance == ex\n\nFor more examples, see the `examples directory on GitHub <https://github.com/jsonpickle/jsonpickle/tree/main/examples>`_ for example scripts. These can be run on your local machine to see how jsonpickle works and behaves, and how to use it. Contributions from users regarding how they use jsonpickle are welcome!\n\n\nWhy jsonpickle?\n===============\n\nData serialized with python's pickle (or cPickle or dill) is not easily readable outside of python. Using the json format, jsonpickle allows simple data types to be stored in a human-readable format, and more complex data types such as numpy arrays and pandas dataframes, to be machine-readable on any platform that supports json. E.g., unlike pickled data, jsonpickled data stored in an Amazon S3 bucket is indexible by Amazon's Athena.\n\nSecurity\n========\n\njsonpickle should be treated the same as the\n`Python stdlib pickle module <https://docs.python.org/3/library/pickle.html>`_\nfrom a security perspective.\n\n.. warning::\n\n   The jsonpickle module **is not secure**.  Only unpickle data you trust.\n\n   It is possible to construct malicious pickle data which will **execute\n   arbitrary code during unpickling**.  Never unpickle data that could have come\n   from an untrusted source, or that could have been tampered with.\n\n   Consider signing data with an HMAC if you need to ensure that it has not\n   been tampered with.\n\n   Safer deserialization approaches, such as reading JSON directly,\n   may be more appropriate if you are processing untrusted data.\n\n\nInstall\n=======\n\nInstall from pip for the latest stable release:\n\n::\n\n    pip install jsonpickle\n\nInstall from github for the latest changes:\n\n::\n\n    pip install git+https://github.com/jsonpickle/jsonpickle.git\n\n\nNumpy/Pandas Support\n====================\n\njsonpickle includes built-in numpy and pandas extensions.  If you would\nlike to encode sklearn models, numpy arrays, pandas DataFrames, and other\nnumpy/pandas-based data, then you must enable the numpy and/or pandas\nextensions by registering their handlers::\n\n    >>> import jsonpickle.ext.numpy as jsonpickle_numpy\n    >>> import jsonpickle.ext.pandas as jsonpickle_pandas\n    >>> jsonpickle_numpy.register_handlers()\n    >>> jsonpickle_pandas.register_handlers()\n\n\nDevelopment\n===========\n\nUse `make` to run the unit tests::\n\n        make test\n\n`pytest` is used to run unit tests internally.\n\nA `tox` target is provided to run tests using all installed and supported Python versions::\n\n        make tox\n\n`jsonpickle` itself has no dependencies beyond the Python stdlib.\n`tox` is required for testing when using the `tox` test runner only.\n\nThe testing requirements are specified in `setup.cfg`.\nIt is recommended to create a virtualenv and run tests from within the\nvirtualenv.::\n\n        python3 -mvenv env3\n        source env3/bin/activate\n        pip install --editable '.[dev]'\n        make test\n\nYou can also use a tool such as `vx <https://github.com/davvid/vx/>`_\nto activate the virtualenv without polluting your shell environment::\n\n        python3 -mvenv env3\n        vx env3 pip install --editable '.[dev]'\n        vx env3 make test\n\nIf you can't use a venv, you can install the testing packages as follows::\n\n        pip install .[testing]\n\n`jsonpickle` supports multiple Python versions, so using a combination of\nmultiple virtualenvs and `tox` is useful in order to catch compatibility\nissues when developing.\n\nGPG Signing\n===========\n\nUnfortunately, while versions of jsonpickle before 3.0.1 should still be signed, GPG signing support was removed from PyPi (https://blog.pypi.org/posts/2023-05-23-removing-pgp/) back in May 2023.\n\nLicense\n=======\n\nLicensed under the BSD License. See COPYING for details.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "jsonpickle encodes/decodes any Python object to/from JSON",
    "version": "4.0.0",
    "project_urls": {
        "Documentation": "https://jsonpickle.readthedocs.io/",
        "Homepage": "https://jsonpickle.readthedocs.io/",
        "Source": "https://github.com/jsonpickle/jsonpickle"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a164815460f86d94c9e1431800a75061719824c6fef14d88a6117eba3126cd5b",
                "md5": "f0fe57bcf478bf141f6d9e8ca5dc9727",
                "sha256": "53730b9e094bc41f540bfdd25eaf6e6cf43811590e9e1477abcec44b866ddcd9"
            },
            "downloads": -1,
            "filename": "jsonpickle-4.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f0fe57bcf478bf141f6d9e8ca5dc9727",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 46157,
            "upload_time": "2024-11-12T04:13:35",
            "upload_time_iso_8601": "2024-11-12T04:13:35.788756Z",
            "url": "https://files.pythonhosted.org/packages/a1/64/815460f86d94c9e1431800a75061719824c6fef14d88a6117eba3126cd5b/jsonpickle-4.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "04b79fb3cb5915f7363ceea7eb433866a69e8c01b43201daf368afd5c2ff722b",
                "md5": "1fcd7d597e394a552f0c8717ce0f6659",
                "sha256": "fc670852b204d77601b08f8f9333149ac37ab6d3fe4e6ed3b578427291f63736"
            },
            "downloads": -1,
            "filename": "jsonpickle-4.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1fcd7d597e394a552f0c8717ce0f6659",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 314587,
            "upload_time": "2024-11-12T04:13:38",
            "upload_time_iso_8601": "2024-11-12T04:13:38.186087Z",
            "url": "https://files.pythonhosted.org/packages/04/b7/9fb3cb5915f7363ceea7eb433866a69e8c01b43201daf368afd5c2ff722b/jsonpickle-4.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-12 04:13:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jsonpickle",
    "github_project": "jsonpickle",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "appveyor": true,
    "tox": true,
    "lcname": "jsonpickle"
}
        
Elapsed time: 0.44477s