Nice to have a simpler option than DRF which has grown into a quite complicated mound of code.
Django Ninja – Fast Django REST Framework for Building APIs
31–35 of 35 posts
Re: Django Ninja – Fast Django REST Framework for Building APIs
#32The approach for this I have taken lately is this: 1. A custom made serializer. This is the most complicated 150 lines of code in that it can traverse Django ORM objects/query sets and output them to JSON. It supports explicit included and excluded fields and included relationships which it automatically prefetches. 2. Custom middleware that parses any application/json request bodies in request.data . 3. I use Django…
Do you have a public repo with examples of this in action?
Frankly it’s not hard to do: you need a parser for author.books.chapters, then a bit of code to look up fields from a model’s Meta class, and then a recursive function to traverse model instances and include the correct field/value pairs based on the type that each field is (scalar, iterable, dict, model instance). My latest version includes a couple of niceties like the annotation on the models of fields to always include/exclude, support for custom properties, and caching of the above. The output is a dict or a list of dicts that can be serialized by Django’s JSON serializer.
Django actually sort of includes a version of this already for serializing model instances, it’s just not very robust.
Re: Django Ninja – Fast Django REST Framework for Building APIs
#33Re: Django Ninja – Fast Django REST Framework for Building APIs
#34> FAST execution: Very high performance thanks to Pydantic and async support. > Benchmark: 750 requests per second. Think we're gonna need a couple of zeroes on that number to throw around words like "very high performance".
this is pure CPU-heavy single core synthetic test - this is just to give an idea how it compares the speed to flask/drf on the same environment
Re: Django Ninja – Fast Django REST Framework for Building APIs
#35I've been using django ninja for months and I can say that it's a very good replacement to DRF. It's way simpler to use and less bloated, thanks to pydantic.
However I would not use it for important projects in production, because of a lack of support and documentation, and the fact that it relies almost entirely on a single developer (like many other projects, right).