Skip to main content

No project description provided

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

generic_json_encoders-0.0.2.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

generic_json_encoders-0.0.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file generic_json_encoders-0.0.2.tar.gz.

File metadata

File hashes

Hashes for generic_json_encoders-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e547d6e1eee56696d2ee16f5bc2bbe7c13a86f5f0420b82dea560c8fe2f6e8b2
MD5 cc69315eb66967fab645da086285b01d
BLAKE2b-256 c52e0bda6b94ac6507c1215316fb9d2bb14ef5f90bbe1d739d339c6d1cc7cb30

See more details on using hashes here.

File details

Details for the file generic_json_encoders-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for generic_json_encoders-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7a631d81e12eb987459228571a45aedd1a0173c130a60baeaa903ad0f2d5acc6
MD5 b493028a6c2bac5d029a9370c8bf3ad0
BLAKE2b-256 7d934898285cef09b21269a4202b97ba4b22596869f6f39d07b578692cec0852

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page