{"id":6610,"library":"drf-orjson-renderer","title":"Django RestFramework JSON Renderer Backed by orjson","description":"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.","status":"active","version":"1.8.0","language":"python","source_language":"en","source_url":"https://github.com/brianjbuck/drf_orjson_renderer","tags":["django","drf","json","performance","renderer","parser","orjson"],"install":[{"cmd":"pip install drf-orjson-renderer","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for high-performance JSON serialization/deserialization.","package":"orjson","optional":false},{"reason":"Required as a DRF renderer/parser.","package":"djangorestframework","optional":false}],"imports":[{"wrong":"from drf_orjson_renderer.renderers import ORJSONRenderer","symbol":"ORJSONRenderer","correct":"from drf_orjson_renderer.renderers import ORJSONRenderer"}],"quickstart":{"code":"import os\n\n# settings.py\n\nREST_FRAMEWORK = {\n    \"DEFAULT_RENDERER_CLASSES\": (\n        \"drf_orjson_renderer.renderers.ORJSONRenderer\",\n        \"rest_framework.renderers.BrowsableAPIRenderer\",\n    ),\n    \"DEFAULT_PARSER_CLASSES\": (\n        \"drf_orjson_renderer.parsers.ORJSONParser\",\n        \"rest_framework.parsers.FormParser\",\n        \"rest_framework.parsers.MultiPartParser\",\n    ),\n    \"ORJSON_RENDERER_OPTIONS\": (\n        # Example options for orjson\n        # import orjson # You would import orjson in settings.py to use these\n        # orjson.OPT_NON_STR_KEYS,\n        # orjson.OPT_SERIALIZE_DATACLASS,\n        # orjson.OPT_SERIALIZE_NUMPY,\n    ),\n}","lang":"python","description":"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`."},"warnings":[{"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).","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"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`.","message":"For 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`.","severity":"gotcha","affected_versions":"All versions"},{"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`.","message":"If 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.","severity":"gotcha","affected_versions":"All 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.","message":"Version 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.","severity":"breaking","affected_versions":"<1.8.0"}],"env_vars":null,"search_vec":"'1.8.0':67 'activ':70 'also':53 'api':42,62 'back':5,31 'boost':41 'browsabl':61 'correct':38 'current':64 'default':49 'django':1,21,74 'drf':9,24,47,75 'drf-orjson-render':8 'framework':23 'high':14 'json':3,16,50,58,76 'leverag':25 'librari':28 'mainten':71 'ongo':69 'orjson':7,10,27,80 'parser':19,79 'perform':15,77 'pretti':56 'pretty-print':55 'print':57 'render':4,11,17,51,78 'replac':46 'respons':43 'rest':22 'restframework':2 'rust':33 'safeti':36 'signific':40 'speed':35 'support':54 'time':44 'updat':73 'version':65","created_at":"2026-04-15T18:35:18.218386+00:00","updated_at":"2026-04-16T14:42:12.034179+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n  File \"/tmp/tmppfgkp5aj/venv/lib/python3.12/site-packages/drf_orjson_renderer/renderers.py\", line 17, in <module>\n    from rest_framework.renderers import BaseRenderer\n  File \"/tmp/tmppfgkp5aj/venv/lib/python3.12/site-package"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.8.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/brianjbuck/drf_orjson_renderer","docs":null,"changelog":null,"pypi":"https://pypi.org/project/drf-orjson-renderer/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}