TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Django Ninja – Fast Django REST Framework for Building APIs

169 pointsby watchdogtimerover 3 years ago

8 comments

samwillisover 3 years ago
This has an explanation of the motivation for this project:<p><a href="https:&#x2F;&#x2F;django-ninja.rest-framework.com&#x2F;motivation&#x2F;" rel="nofollow">https:&#x2F;&#x2F;django-ninja.rest-framework.com&#x2F;motivation&#x2F;</a><p>It sounds super interesting, it fits the middle ground between Django Rest Framework and FastAPI taking the best of both. Full support for Django and particularly it’s ORM (hard to do with FastAPI as the Django ORM is not yet async and can’t be used with FastAPI)<p>I like that it supports both sync and async as I’m personally not convinced about the use of async Python everywhere. I could see this being brilliant for an api where the majority is simple sync code but with a few endpoint with long running responses or where you need multiple concurrent requests to DBS or other APIs.<p>(Edited for clarity, thanks vladvasiliu)
评论 #30223288 未加载
fredrikholmover 3 years ago
&gt; FAST execution: Very high performance thanks to Pydantic and async support.<p>&gt; Benchmark: 750 requests per second.<p>Think we&#x27;re gonna need a couple of zeroes on that number to throw around words like &quot;very high performance&quot;.
评论 #30233062 未加载
IgorPartolaover 3 years ago
The approach for this I have taken lately is this:<p>1. A custom made serializer. This is the most complicated 150 lines of code in that it can traverse Django ORM objects&#x2F;query sets and output them to JSON. It supports explicit included and excluded fields and included relationships which it automatically prefetches.<p>2. Custom middleware that parses any application&#x2F;json request bodies in <i>request.data</i>.<p>3. I use Django forms on any data going from client to server for validation. Works great, no reason to make this complicated.<p>That’s it. Now I can have a REST API written as normal Django views. It is significantly more performant Thant DRF since it doesn’t need to check for a whole lot of different complicated field types when serializing. It’s easy to understand (just call <i>serialize(users, excluded_fields=[“password”], relationships=[“books.chapters”])</i> to return JSON to the client; you can also annotate your models to include&#x2F;exclude fields and relationships by default). It has validation errors built in via Django forms. It just works.
评论 #30224790 未加载
评论 #30228865 未加载
dplgkover 3 years ago
Nice to have a simpler option than DRF which has grown into a quite complicated mound of code.
评论 #30225506 未加载
评论 #30223389 未加载
评论 #30224955 未加载
评论 #30229657 未加载
bluewaltover 3 years ago
This project is very clever, because as a Django developer, when I tried to use. FastAPI, I didn&#x27;t get the faith to learn another ORM.<p>I&#x27;ve been using django ninja for months and I can say that it&#x27;s a very good replacement to DRF. It&#x27;s way simpler to use and less bloated, thanks to pydantic.<p>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).
todotaskover 3 years ago
When I read the tutorial and run on uvicorn with my lack of experience in Python language, it&#x27;s significantly slow (3,000+ rps using this framework manage.py vs &lt;500 rps on uvicorn)?
nesarkvechnepover 3 years ago
Unfortunately, it doesn&#x27;t enforce usage of hypertext.
fraysover 3 years ago
Will check this out. Thanks for sharing.