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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file generic_json_encoders-0.0.2.tar.gz
.
File metadata
- Download URL: generic_json_encoders-0.0.2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e547d6e1eee56696d2ee16f5bc2bbe7c13a86f5f0420b82dea560c8fe2f6e8b2 |
|
MD5 | cc69315eb66967fab645da086285b01d |
|
BLAKE2b-256 | c52e0bda6b94ac6507c1215316fb9d2bb14ef5f90bbe1d739d339c6d1cc7cb30 |
File details
Details for the file generic_json_encoders-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: generic_json_encoders-0.0.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a631d81e12eb987459228571a45aedd1a0173c130a60baeaa903ad0f2d5acc6 |
|
MD5 | b493028a6c2bac5d029a9370c8bf3ad0 |
|
BLAKE2b-256 | 7d934898285cef09b21269a4202b97ba4b22596869f6f39d07b578692cec0852 |