Registry / web-framework / djangorestframework-camel-case

djangorestframework-camel-case

JSON →
library1.4.2pypypiunverified

djangorestframework-camel-case (version 1.4.2) is an active Python library that provides seamless camel case JSON support for Django REST framework. It automatically converts API request and response fields between Python's `snake_case` and JavaScript's `camelCase`, allowing developers to maintain consistent Pythonic naming conventions while exposing JavaScript-friendly APIs. The library was last updated in February 2023.

pip install djangorestframework-camel-case
INSTALL
IMPORT
SIG · DJANGORESTFRAMEWOR
D
djangorestframework-camel-case
web-frameworkpythonv1.4.2
Install
3.2s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.2 · 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 · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.2s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

CamelCaseJSONRenderer
from djangorestframework_camel_case.render import CamelCaseJSONRenderer
from djangorestframework_camel_case.render import CamelCaseJSONRenderer
CamelCaseJSONParser
from djangorestframework_camel_case.parser import CamelCaseJSONParser
from djangorestframework_camel_case.parser import CamelCaseJSONParser
CamelCaseMiddleware
from djangorestframework_camel_case.middleware import CamelCaseMiddleware
from djangorestframework_camel_case.middleware import CamelCaseMiddleware

To quickly enable camel case conversion, configure the `DEFAULT_RENDERER_CLASSES` and `DEFAULT_PARSER_CLASSES` in your `settings.py` to use the provided camel case renderers and parsers. You can also add `CamelCaseMiddleWare` for query parameter conversion.

import os # In your Django settings.py file REST_FRAMEWORK = { 'DEFAULT_RENDERER_CLASSES': [ 'djangorestframework_camel_case.render.CamelCaseJSONRenderer', 'djangorestframework_camel_case.render.CamelCaseBrowsableAPIRenderer', # Optional 'rest_framework.renderers.JSONRenderer', 'rest_framework.renderers.BrowsableAPIRenderer', ], 'DEFAULT_PARSER_CLASSES': [ 'djangorestframework_camel_case.parser.CamelCaseJSONParser', 'djangorestframework_camel_case.parser.CamelCaseFormParser', # Optional 'djangorestframework_camel_case.parser.CamelCaseMultiPartParser', # Optional 'rest_framework.parsers.JSONParser', 'rest_framework.parsers.FormParser', 'rest_framework.parsers.MultiPartParser', ], } # Optionally, add middleware for query parameter conversion # In your Django settings.py file, in the MIDDLEWARE list MIDDLEWARE = [ # ... other middleware ... 'djangorestframework_camel_case.middleware.CamelCaseMiddleWare', # ... ] # Example of how you might integrate with a custom renderer (e.g., ORJSON) # JSON_CAMEL_CASE = { # 'RENDERER_CLASS': 'drf_orjson_renderer.renderers.ORJSONRenderer' # } # Example of customizing underscoreization for specific cases (e.g., v2Counter -> v2_counter) # REST_FRAMEWORK = { # 'JSON_UNDERSCOREIZE': { # 'no_underscore_before_number': True, # }, # # ... other DRF settings ... # } # A basic DRF serializer example (Python snake_case) from rest_framework import serializers class MyModelSerializer(serializers.Serializer): my_field_name = serializers.CharField(max_length=100) another_data_point = serializers.IntegerField() # When rendered by CamelCaseJSONRenderer, it will appear as: # { # "myFieldName": "value", # "anotherDataPoint": 123 # }
Debug
Known issues
gotchaWhen testing with `APITestCase`, `response.data` will contain `snake_case` keys, while the actual `camelCase` output is found in `json.loads(response.content)`. Ensure your assertions target the correct response parameter.
fix
Use `json.loads(response.content)` for assertions in tests when expecting camel case output.
affects: All versions
gotchaThe package uses a default underscoreization convention (e.g., `v2Counter` -> `v_2_counter`). If you prefer an alternative convention (e.g., `v2Counter` -> `v2_counter`), you must explicitly configure `JSON_UNDERSCOREIZE` in your `settings.py` or as a class attribute on parsers.
fix
Set `REST_FRAMEWORK = {'JSON_UNDERSCOREIZE': {'no_underscore_before_number': True}}` in `settings.py` or `json_underscoreize = {'no_underscore_before_number': True}` on your parser class.
affects: All versions
gotchaIf you intend to use a different base JSON renderer (e.g., `drf_orjson_renderer`, `drf_ujson_renderer`), you must specify it within the `JSON_CAMEL_CASE` setting in `settings.py`, not directly in `DEFAULT_RENDERER_CLASSES` as the primary renderer.
fix
Configure `JSON_CAMEL_CASE = {'RENDERER_CLASS': 'your_custom_renderer_path'}` in `settings.py`.
affects: All versions
gotchaFor proper camel case representation in OpenAPI schemas generated by `drf-spectacular`, an additional post-processing hook needs to be configured in your `SPECTACULAR_SETTINGS`.
fix
Add `'drf_spectacular.contrib.djangorestframework_camel_case.camelize_serializer_fields'` to `POSTPROCESSING_HOOKS` in your `SPECTACULAR_SETTINGS`.
affects: All versions
Upgrade
Version history
1.4.2latest on PyPI · released Feb 13, 2023
Audit
Dependencies
djangorestframeworkrequiredThis library is an extension for Django REST Framework and requires it to function.
Agent activity
4 hits · last 30 days
node
4
Resources
djangorestframework-camel-case — pip install djangorestframework-camel-case · libregistry