Metadata-Version: 2.1
Name: sdjson
Version: 0.3.0
Summary: Custom JSON Encoder for Python utilising functools.singledispatch to support custom encoders for both Python's built-in classes and user-created classes, without as much legwork.
Home-page: https://github.com/domdfcoding/singledispatch-json
Author: Dominic Davis-Foster
Author-email: dominic@davis-foster.co.uk
License: GNU Lesser General Public License v3 or later (LGPLv3+)
Project-URL: Documentation, https://singledispatch-json.readthedocs.io
Project-URL: Issue_Tracker, https://github.com/domdfcoding/singledispatch-json/issues
Project-URL: Source_Code, https://github.com/domdfcoding/singledispatch-json
Description: =======
        sdjson
        =======
        
        .. start short_desc
        
        **Custom JSON Encoder for Python utilising functools.singledispatch to support custom encoders for both Python's built-in classes and user-created classes, without as much legwork.**
        
        .. end short_desc
        
        .. start shields
        
        .. list-table::
        	:stub-columns: 1
        	:widths: 10 90
        
        	* - Docs
        	  - |docs| |docs_check|
        	* - Tests
        	  - |travis| |actions_windows| |actions_macos| |coveralls| |codefactor|
        	* - PyPI
        	  - |pypi-version| |supported-versions| |supported-implementations| |wheel|
        	* - Anaconda
        	  - |conda-version| |conda-platform|
        	* - Activity
        	  - |commits-latest| |commits-since| |maintained|
        	* - Other
        	  - |license| |language| |requires| |pre_commit|
        
        .. |docs| image:: https://img.shields.io/readthedocs/singledispatch-json/latest?logo=read-the-docs
        	:target: https://singledispatch-json.readthedocs.io/en/latest/?badge=latest
        	:alt: Documentation Build Status
        
        .. |docs_check| image:: https://github.com/domdfcoding/singledispatch-json/workflows/Docs%20Check/badge.svg
        	:target: https://github.com/domdfcoding/singledispatch-json/actions?query=workflow%3A%22Docs+Check%22
        	:alt: Docs Check Status
        
        .. |travis| image:: https://img.shields.io/travis/com/domdfcoding/singledispatch-json/master?logo=travis
        	:target: https://travis-ci.com/domdfcoding/singledispatch-json
        	:alt: Travis Build Status
        
        .. |actions_windows| image:: https://github.com/domdfcoding/singledispatch-json/workflows/Windows%20Tests/badge.svg
        	:target: https://github.com/domdfcoding/singledispatch-json/actions?query=workflow%3A%22Windows+Tests%22
        	:alt: Windows Tests Status
        
        .. |actions_macos| image:: https://github.com/domdfcoding/singledispatch-json/workflows/macOS%20Tests/badge.svg
        	:target: https://github.com/domdfcoding/singledispatch-json/actions?query=workflow%3A%22macOS+Tests%22
        	:alt: macOS Tests Status
        
        .. |requires| image:: https://requires.io/github/domdfcoding/singledispatch-json/requirements.svg?branch=master
        	:target: https://requires.io/github/domdfcoding/singledispatch-json/requirements/?branch=master
        	:alt: Requirements Status
        
        .. |coveralls| image:: https://img.shields.io/coveralls/github/domdfcoding/singledispatch-json/master?logo=coveralls
        	:target: https://coveralls.io/github/domdfcoding/singledispatch-json?branch=master
        	:alt: Coverage
        
        .. |codefactor| image:: https://img.shields.io/codefactor/grade/github/domdfcoding/singledispatch-json?logo=codefactor
        	:target: https://www.codefactor.io/repository/github/domdfcoding/singledispatch-json
        	:alt: CodeFactor Grade
        
        .. |pypi-version| image:: https://img.shields.io/pypi/v/sdjson
        	:target: https://pypi.org/project/sdjson/
        	:alt: PyPI - Package Version
        
        .. |supported-versions| image:: https://img.shields.io/pypi/pyversions/sdjson?logo=python&logoColor=white
        	:target: https://pypi.org/project/sdjson/
        	:alt: PyPI - Supported Python Versions
        
        .. |supported-implementations| image:: https://img.shields.io/pypi/implementation/sdjson
        	:target: https://pypi.org/project/sdjson/
        	:alt: PyPI - Supported Implementations
        
        .. |wheel| image:: https://img.shields.io/pypi/wheel/sdjson
        	:target: https://pypi.org/project/sdjson/
        	:alt: PyPI - Wheel
        
        .. |conda-version| image:: https://img.shields.io/conda/v/domdfcoding/sdjson?logo=anaconda
        	:target: https://anaconda.org/domdfcoding/sdjson
        	:alt: Conda - Package Version
        
        .. |conda-platform| image:: https://img.shields.io/conda/pn/domdfcoding/sdjson?label=conda%7Cplatform
        	:target: https://anaconda.org/domdfcoding/sdjson
        	:alt: Conda - Platform
        
        .. |license| image:: https://img.shields.io/github/license/domdfcoding/singledispatch-json
        	:target: https://github.com/domdfcoding/singledispatch-json/blob/master/LICENSE
        	:alt: License
        
        .. |language| image:: https://img.shields.io/github/languages/top/domdfcoding/singledispatch-json
        	:alt: GitHub top language
        
        .. |commits-since| image:: https://img.shields.io/github/commits-since/domdfcoding/singledispatch-json/v0.3.0
        	:target: https://github.com/domdfcoding/singledispatch-json/pulse
        	:alt: GitHub commits since tagged version
        
        .. |commits-latest| image:: https://img.shields.io/github/last-commit/domdfcoding/singledispatch-json
        	:target: https://github.com/domdfcoding/singledispatch-json/commit/master
        	:alt: GitHub last commit
        
        .. |maintained| image:: https://img.shields.io/maintenance/yes/2020
        	:alt: Maintenance
        
        .. |pre_commit| image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
        	:target: https://github.com/pre-commit/pre-commit
        	:alt: pre-commit
        
        .. end shields
        
        |
        
        Usage
        #########
        Creating and registering a custom encoder is as easy as:
        
        >>> import sdjson
        >>>
        >>> @sdjson.dump.register(MyClass)
        >>> def encode_myclass(obj):
        ...     return dict(obj)
        >>>
        
        In this case, ``MyClass`` can be made JSON-serializable simply by calling
        ``dict()`` on it. If your class requires more complicated logic
        to make it JSON-serializable, do that here.
        
        Then, to dump the object to a string:
        
        >>> class_instance = MyClass()
        >>> print(sdjson.dumps(class_instance))
        '{"menu": ["egg and bacon", "egg sausage and bacon", "egg and spam", "egg bacon and spam"],
        "today\'s special": "Lobster Thermidor au Crevette with a Mornay sauce served in a Provencale
        manner with shallots and aubergines garnished with truffle pate, brandy and with a fried egg
        on top and spam."}'
        >>>
        
        Or to dump to a file:
        
        >>> with open("spam.json", "w") as fp:
        ...     sdjson.dumps(class_instance, fp)
        ...
        >>>
        
        ``sdjson`` also provides access to ``load``, ``loads``, ``JSONDecoder``,
        ``JSONDecodeError``, and ``JSONEncoder`` from the ``json`` module,
        allowing you to use ``sdjson`` as a drop-in replacement
        for ``json``.
        
        If you wish to dump an object without using the custom encoders, you
        can pass a different ``JSONEncoder`` subclass, or indeed ``JSONEncoder``
        itself to get the stock functionality.
        
        >>> sdjson.dumps(class_instance, cls=sdjson.JSONEncoder)
        >>>
        
        |
        
        When you've finished, if you want to unregister the encoder you can call:
        
        >>> sdjson.encoders.unregister(MyClass)
        >>>
        
        to remove the encoder for ``MyClass``. If you want to replace the encoder with a
        different one it is not necessary to call this function: the
        ``@sdjson.encoders.register`` decorator will replace any existing decorator for
        the given class.
        
        
        Note that this module cannot be used to create custom encoders for any object
        ``json`` already knows about; that is: ``dict``, ``list``, ``tuple``, ``str``,
        ``int``, ``float``, ``bool``, and ``None``.
        
        TODO
        ######
        
        1. Add support for custom decoders.
        
Platform: Windows
Platform: macOS
Platform: Linux
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Requires-Python: >=3.6
Description-Content-Type: text/x-rst
Provides-Extra: all
