Registry / web-framework / drf-orjson-renderer

drf-orjson-renderer

JSON →
library1.8.0pypypiunverified

drf-orjson-renderer is a highly performant JSON renderer and parser for Django Rest Framework (DRF), leveraging the `orjson` library, which is backed by Rust for speed, safety, and correctness. It significantly boosts API response times by replacing DRF's default JSON renderer and also supports pretty-printed JSON for the Browsable API. The current version is 1.8.0, with ongoing active maintenance and updates.

pip install drf-orjson-renderer
INSTALL
IMPORT
SIG · DRF-ORJSON-RENDERE
D
drf-orjson-renderer
web-frameworkpythonv1.8.0
Install
4.0s avg
Import
Disk
70MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 71MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 4.0s · import 0.000s · 71MB
70MB installed
● package 70MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ORJSONRenderer
from drf_orjson_renderer.renderers import ORJSONRenderer
from drf_orjson_renderer.renderers import ORJSONRenderer

To quickly integrate `drf-orjson-renderer`, add `ORJSONRenderer` and `ORJSONParser` to your `DEFAULT_RENDERER_CLASSES` and `DEFAULT_PARSER_CLASSES` respectively in your Django `settings.py`. You can also configure `orjson` specific serialization options using `ORJSON_RENDERER_OPTIONS`.

import os # settings.py REST_FRAMEWORK = { "DEFAULT_RENDERER_CLASSES": ( "drf_orjson_renderer.renderers.ORJSONRenderer", "rest_framework.renderers.BrowsableAPIRenderer", ), "DEFAULT_PARSER_CLASSES": ( "drf_orjson_renderer.parsers.ORJSONParser", "rest_framework.parsers.FormParser", "rest_framework.parsers.MultiPartParser", ), "ORJSON_RENDERER_OPTIONS": ( # Example options for orjson # import orjson # You would import orjson in settings.py to use these # orjson.OPT_NON_STR_KEYS, # orjson.OPT_SERIALIZE_DATACLASS, # orjson.OPT_SERIALIZE_NUMPY, ), }
Debug
Known issues
gotchaWhen configuring `ORJSON_RENDERER_OPTIONS` in `settings.py`, ensure that any `orjson.OPT_*` flags are correctly imported from `orjson` within your settings file or defined as constants.
fix
Import `orjson` directly in `settings.py` to reference `orjson.OPT_*` flags, or define the integer values of these flags if `orjson` cannot be directly imported at `settings.py` parse time (though direct import is generally preferred and recommended in the official documentation).
affects: All versions
gotchaFor custom serialization of objects not natively supported by `orjson` (e.g., custom Python classes), you may need to provide a `default` function. This is typically done by overriding the `get_renderer_context()` method within your DRF `APIView` or `ViewSet`.
fix
Override `get_renderer_context` in your view and pass a custom `default` callable in the context that `orjson` can use to serialize unrecognized types. For example: `context['default'] = your_custom_serializer_func`.
affects: All versions
gotchaIf you are manually creating and returning `ORJsonResponse` instances (rather than letting DRF's renderer handle it), you might encounter a `TypeError` for non-dictionary root objects. This is because `orjson` (and standard JSON) expects the top-level object to be a dictionary or list.
fix
When instantiating `ORJsonResponse` directly with a non-dictionary or non-list object as the top level, you must pass `safe=False` (e.g., `ORJsonResponse(data, safe=False)`). The library's renderer handles this automatically, but direct usage requires explicit handling. Ensure your response data is serializable by `orjson`.
affects: All versions
breakingVersion 1.8.0 specifically added support for NumPy 2.0. While `orjson` generally handles NumPy types, older `drf-orjson-renderer` versions might have had specific internal encoders or different compatibility with newer NumPy versions.
fix
Upgrade to `drf-orjson-renderer` version 1.8.0 or higher to ensure full compatibility with NumPy 2.0 and potentially improved handling of NumPy data types.
affects: <1.8.0
Upgrade
Version history
1.8.0latest on PyPI · released Dec 17, 2025
Audit
Dependencies
orjsonrequiredCore dependency for high-performance JSON serialization/deserialization.
djangorestframeworkrequiredRequired as a DRF renderer/parser.
Agent activity
15 hits · last 30 days
node
14
Resources
drf-orjson-renderer — pip install drf-orjson-renderer · libregistry