https://github.com/devkral/generic-json-encoders
More speedier and correct lilya like encoders
https://github.com/devkral/generic-json-encoders
Last synced: 3 months ago
JSON representation
More speedier and correct lilya like encoders
- Host: GitHub
- URL: https://github.com/devkral/generic-json-encoders
- Owner: devkral
- License: bsd-3-clause
- Created: 2024-11-19T12:30:38.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-14T15:37:41.000Z (12 months ago)
- Last Synced: 2025-09-03T08:54:25.072Z (9 months ago)
- Language: Python
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# generic-json-encoders
**THIS PROJECT IS DEPRECATED!!!!!!**
I got the changes implemented in lilya.
A speedier version of the lilya encoders with more correct results and support for pydantic and msgspec.
It uses under the hood orjson.
[](https://pypi.org/project/generic-json-encoders)
[](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.