2 hours ago · Tech · hide · 0 comments

Just as cars painted red are known to be faster, libraries implemented in Rust are also known to be faster. Today’s example is orjson, a Rusty replacement for Python’s built-in json module, boasting 10x faster serialization and 2x faster deserialization. Such a library is great, but adopting it isn’t easy, especially when your framework uses json in many different parts. To help Django developers adopt orjson, I have created django-orjson, which provides a whole bunch of drop-in replacements for Django and Django REST Framework (DRF) components backed by orjson. For example, there’s a version of JsonResponse: from django_orjson.http import JsonResponse def index(request): return JsonResponse({"title": "Hello, world!"}) …a test client with matching test case classes: from django_orjson.test import SimpleTestCase class IndexTests(SimpleTestCase): def test_index(self): response = self.client.get("/", headers={"accept": "application/json"}) assert response.status_code == 200 #…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.