generic-json-encoders


Namegeneric-json-encoders JSON
Version 0.0.2 PyPI version JSON
download
home_pageNone
SummaryNone
upload_time2024-11-20 17:55:05
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseCopyright © 2024, devkral@web.de. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords encoders esmerald lilya
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # generic-json-encoders

A speedier version of the lilya encoders with more correct results and support for pydantic and msgspec.
It uses under the hood orjson.

[![PyPI - Version](https://img.shields.io/pypi/v/generic-json-encoders.svg)](https://pypi.org/project/generic-json-encoders)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/generic-json-encoders.svg)](https://pypi.org/project/generic-json-encoders)

-----

## Table of Contents

- [Installation](#installation)
- [License](#license)

## Installation

```console
pip install generic-json-encoders
```

## Usage

**Basic**


``` python
import datetime
from decimal import Decimal
from generic_json_encoders import json_encode, simplify

test_obj = {
    "datetime": datetime.datetime.now(),
    "date": datetime.date.today(),
    "decimal": Decimal("0.3").
}

# get json byte string
print(json_encode(test_obj))
# get simplified json serializable object
print(json_encode(test_obj))
```

**Advanced**

`generic_json_encoders` can also apply annotations in esmerald style. However the annotations must be evaluated.


``` python
import datetime
from functools import partial
from decimal import Decimal
from generic_json_encoders import apply_annotation

apply_annotation("2.333", Decimal)
apply_annotation("2.333", Decimal, partial(transform_fn=simplify))
```


### Integrating in lilya

Put somewhere in the init code of your application

``` python
from importlib import import_module
from contextlib import suppress

...
with suppress(ImportError):
    import_module("generic_json_encoders.lilya_monkey_patcher")
...

```

### Integrating in esmerald

``` python
import esmerald

from generic_json_encoders.lilya_monkey_patcher import GenericJsonEncoder

# you need it here too, for registering at the first place
app = esmerald.Esmerald(encoders=[GenericJsonEncoder()])

```


## License

`generic-json-encoders` is distributed under the terms of the [BSD](https://spdx.org/licenses/BSD-3-Clause.html) license.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "generic-json-encoders",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "encoders, esmerald, lilya",
    "author": null,
    "author_email": "alex <devkral@web.de>",
    "download_url": "https://files.pythonhosted.org/packages/c5/2e/0bda6b94ac6507c1215316fb9d2bb14ef5f90bbe1d739d339c6d1cc7cb30/generic_json_encoders-0.0.2.tar.gz",
    "platform": null,
    "description": "# generic-json-encoders\n\nA speedier version of the lilya encoders with more correct results and support for pydantic and msgspec.\nIt uses under the hood orjson.\n\n[![PyPI - Version](https://img.shields.io/pypi/v/generic-json-encoders.svg)](https://pypi.org/project/generic-json-encoders)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/generic-json-encoders.svg)](https://pypi.org/project/generic-json-encoders)\n\n-----\n\n## Table of Contents\n\n- [Installation](#installation)\n- [License](#license)\n\n## Installation\n\n```console\npip install generic-json-encoders\n```\n\n## Usage\n\n**Basic**\n\n\n``` python\nimport datetime\nfrom decimal import Decimal\nfrom generic_json_encoders import json_encode, simplify\n\ntest_obj = {\n    \"datetime\": datetime.datetime.now(),\n    \"date\": datetime.date.today(),\n    \"decimal\": Decimal(\"0.3\").\n}\n\n# get json byte string\nprint(json_encode(test_obj))\n# get simplified json serializable object\nprint(json_encode(test_obj))\n```\n\n**Advanced**\n\n`generic_json_encoders` can also apply annotations in esmerald style. However the annotations must be evaluated.\n\n\n``` python\nimport datetime\nfrom functools import partial\nfrom decimal import Decimal\nfrom generic_json_encoders import apply_annotation\n\napply_annotation(\"2.333\", Decimal)\napply_annotation(\"2.333\", Decimal, partial(transform_fn=simplify))\n```\n\n\n### Integrating in lilya\n\nPut somewhere in the init code of your application\n\n``` python\nfrom importlib import import_module\nfrom contextlib import suppress\n\n...\nwith suppress(ImportError):\n    import_module(\"generic_json_encoders.lilya_monkey_patcher\")\n...\n\n```\n\n### Integrating in esmerald\n\n``` python\nimport esmerald\n\nfrom generic_json_encoders.lilya_monkey_patcher import GenericJsonEncoder\n\n# you need it here too, for registering at the first place\napp = esmerald.Esmerald(encoders=[GenericJsonEncoder()])\n\n```\n\n\n## License\n\n`generic-json-encoders` is distributed under the terms of the [BSD](https://spdx.org/licenses/BSD-3-Clause.html) license.\n",
    "bugtrack_url": null,
    "license": "Copyright \u00a9 2024, devkral@web.de. All rights reserved.\n        \n        Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n        \n        1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n        \n        2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n        \n        3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n        \n        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \u201cAS IS\u201d AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
    "summary": null,
    "version": "0.0.2",
    "project_urls": {
        "Documentation": "https://github.com/devkral/generic-json-encoders#readme",
        "Issues": "https://github.com/devkral/generic-json-encoders/issues",
        "Source": "https://github.com/devkral/generic-json-encoders"
    },
    "split_keywords": [
        "encoders",
        " esmerald",
        " lilya"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7d934898285cef09b21269a4202b97ba4b22596869f6f39d07b578692cec0852",
                "md5": "b493028a6c2bac5d029a9370c8bf3ad0",
                "sha256": "7a631d81e12eb987459228571a45aedd1a0173c130a60baeaa903ad0f2d5acc6"
            },
            "downloads": -1,
            "filename": "generic_json_encoders-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b493028a6c2bac5d029a9370c8bf3ad0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6899,
            "upload_time": "2024-11-20T17:55:06",
            "upload_time_iso_8601": "2024-11-20T17:55:06.847531Z",
            "url": "https://files.pythonhosted.org/packages/7d/93/4898285cef09b21269a4202b97ba4b22596869f6f39d07b578692cec0852/generic_json_encoders-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c52e0bda6b94ac6507c1215316fb9d2bb14ef5f90bbe1d739d339c6d1cc7cb30",
                "md5": "cc69315eb66967fab645da086285b01d",
                "sha256": "e547d6e1eee56696d2ee16f5bc2bbe7c13a86f5f0420b82dea560c8fe2f6e8b2"
            },
            "downloads": -1,
            "filename": "generic_json_encoders-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "cc69315eb66967fab645da086285b01d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 6229,
            "upload_time": "2024-11-20T17:55:05",
            "upload_time_iso_8601": "2024-11-20T17:55:05.809817Z",
            "url": "https://files.pythonhosted.org/packages/c5/2e/0bda6b94ac6507c1215316fb9d2bb14ef5f90bbe1d739d339c6d1cc7cb30/generic_json_encoders-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-20 17:55:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "devkral",
    "github_project": "generic-json-encoders#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "generic-json-encoders"
}
        
Elapsed time: 0.34848s