Django RestFramework JSON Renderer Backed by orjson

1.8.0 · active · verified Wed Apr 15

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.

Warnings

Install

Imports

Quickstart

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,
    ),
}

view raw JSON →