Skip to main content

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 PyPI - Python Version


Table of Contents

Installation

pip install generic-json-encoders

Usage

Basic

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.

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

from importlib import import_module
from contextlib import suppress

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

Integrating in esmerald

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 license.

Metadata

Release files for generic-json-encoders 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for generic-json-encoders 0.0.2
File Size Uploaded
generic_json_encoders-0.0.2.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for generic-json-encoders 0.0.2
File Interpreter ABI Platform
generic_json_encoders-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.1 kB

Release files / generic_json_encoders-0.0.2.tar.gz

Download URL generic_json_encoders-0.0.2.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e547d6e1eee56696d2ee16f5bc2bbe7c13a86f5f0420b82dea560c8fe2f6e8b2
BLAKE2b-256 checksum
How to use checksums
c52e0bda6b94ac6507c1215316fb9d2bb14ef5f90bbe1d739d339c6d1cc7cb30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Release files / generic_json_encoders-0.0.2-py3-none-any.whl

Download URL generic_json_encoders-0.0.2-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a631d81e12eb987459228571a45aedd1a0173c130a60baeaa903ad0f2d5acc6
BLAKE2b-256 checksum
How to use checksums
7d934898285cef09b21269a4202b97ba4b22596869f6f39d07b578692cec0852
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page