Django Rest Framework UJSON Renderer
Project description
Django Rest Framework UJSON Renderer
Django Rest Framework renderer using ujson
Installation
pip install drf_ujson
You can then set the UJSONRenderer class as your default renderer in your settings.py
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'drf_ujson.renderers.UJSONRenderer',
),
...
}
Also you can set the UJSONParser class as your default parser in your settings.py
REST_FRAMEWORK = {
'DEFAULT_PARSER_CLASSES': (
'drf_ujson.parsers.UJSONParser',
),
...
}
Benchmarks
This is on average 2.3x faster than the default JSON Serializer.
import timeit
setup = '''
from proposals.models import Proposal
from proposals.serializers import ProposalSerializer
from rest_framework.renderers import JSONRenderer
from drf_ujson.renderers import UJSONRenderer
proposals = Proposal.objects.all()
serialized = ProposalSerializer(proposals, many=True).data
'''
stdlib_test = '''
JSONRenderer().render(serialized)
'''
ujson_test = '''
UJSONRenderer().render(serialized)
'''
stdlib_result = timeit.repeat(stdlib_test, setup=setup, number=1, repeat=10)
ujson_result = timeit.repeat(ujson_test, setup=setup, number=1, repeat=10)
print stdlib_result
print sum(stdlib_result) / 10
print ujson_result
print sum(ujson_result) / 10
# stdlib results
[
0.004502058029174805,
0.004289865493774414,
0.006896018981933594,
0.0048198699951171875,
0.004084110260009766,
0.007154941558837891,
0.003937959671020508,
0.004029035568237305,
0.004770040512084961,
0.004539966583251953
]
# avg
0.00490238666534
# ujson results
[
0.0016620159149169922,
0.001817941665649414,
0.0015261173248291016,
0.0040950775146484375,
0.0021469593048095703,
0.001798868179321289,
0.001569986343383789,
0.0019931793212890625,
0.0017120838165283203,
0.001814126968383789
]
# avg
0.00201363563538
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drf_ujson2-1.2.1.tar.gz.
File metadata
- Download URL: drf_ujson2-1.2.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
768696aec654db9123561ad58ace52ed6f35b91615ecb2ff26b93b1c5ea2876d
|
|
| MD5 |
64946349a65a85d8b0fa42e83780fd0c
|
|
| BLAKE2b-256 |
2cfe274e030c85d402bf9b865df793d974d4e13514e5644ecbc2559298c5c30d
|
File details
Details for the file drf_ujson2-1.2.1-py3-none-any.whl.
File metadata
- Download URL: drf_ujson2-1.2.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f042958cf3ff8214b0fe46556164d630f9ed85f95103f3f49d1237c918903e6
|
|
| MD5 |
f0c6daa23f306b17d9275262abe772e7
|
|
| BLAKE2b-256 |
66cdd581fe5f6e63335bfabf46bbde9965719957745c04059c4c62d10ef02e04
|