Live data from Hacker News

Django Ninja – Fast Django REST Framework for Building APIs

github.com

31–35 of 35 posts

Re: Django Ninja – Fast Django REST Framework for Building APIs

#31
post #2

Nice to have a simpler option than DRF which has grown into a quite complicated mound of code.

I like the idea of DRF, but when I only dive into it occasionally, I find it has much too much magic for my liking. "Just defined this class w/ this property and then it `just works`!" is really hard to follow if you're not familiar with it.

Re: Django Ninja – Fast Django REST Framework for Building APIs

#32
post #27

The 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?

Unfortunately no, but I will see if I can at some point open it up. It’s used at $DAYJOB though the original inspiration came from a personal project so I need to untangle that.

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

#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".

@fredrikholm

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

#35
This project is very clever, because as a Django developer, when I tried to use. FastAPI, I didn't get the faith to learn another ORM.

I'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).

Post reply on HN