Live data from Hacker News

Django Ninja – Fast Django REST Framework for Building APIs

github.com

1–10 of 35 posts

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

#3
This has an explanation of the motivation for this project:

https://django-ninja.rest-framework.com/motivation/

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)

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.

(Edited for clarity, thanks vladvasiliu)

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

#4

This has an explanation of the motivation for this project: https://django-ninja.rest-framework.com/motivation/ 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) I like that it supports both sync and async…

> Full support for Django and particularly it’s ORM (hard to do with FastAPI as the ORM is not yet async)

I think you may have it backwards. Django's ORM isn't async yet [1], whereas FastAPI doesn't actually have an "included" ORM. However, the docs give an example of an async ORM [2], and SQLAlchemy also has async support [3].

---

[1] https://docs.djangoproject.com/en/4.0/topics/async/: We’re still working on async support for the ORM

[2] https://fastapi.tiangolo.com/advanced/async-sql-databases/

[3] https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.htm...

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

#5

This has an explanation of the motivation for this project: https://django-ninja.rest-framework.com/motivation/ 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) I like that it supports both sync and async…

> Full support for Django and particularly it’s ORM (hard to do with FastAPI as the ORM is not yet async) I think you may have it backwards. Django's ORM isn't async yet [1], whereas FastAPI doesn't actually have an "included" ORM. However, the docs give an example of an async ORM [2], and SQLAlchemy also has async support [3]. --- [1] https://docs.djangoproject.com/en/4.0/topics/async/ : We’re still working on async…

No, sorry, did have it right but wasn't clear in my sentence:

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)

Will edit to make clear.

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

#6
post #2

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

If your needs are simple enough, built-in Django function-based views will do. When you outgrow those, DRF's complexity is often warranted.

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

#7
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 forms on any data going from client to server for validation. Works great, no reason to make this complicated.

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 serialize(users, excluded_fields=[“password”], relationships=[“books.chapters”]) to return JSON to the client; you can also annotate your models to include/exclude fields and relationships by default). It has validation errors built in via Django forms. It just works.

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

#8

This has an explanation of the motivation for this project: https://django-ninja.rest-framework.com/motivation/ 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) I like that it supports both sync and async…

> Full support for Django and particularly it’s ORM (hard to do with FastAPI as the ORM is not yet async) I think you may have it backwards. Django's ORM isn't async yet [1], whereas FastAPI doesn't actually have an "included" ORM. However, the docs give an example of an async ORM [2], and SQLAlchemy also has async support [3]. --- [1] https://docs.djangoproject.com/en/4.0/topics/async/ : We’re still working on async…

The author of FastApi wrote an ORM too:

https://github.com/tiangolo/sqlmodel

I have not yet used it, but I think that’s the best approach now

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

#9
post #6
post #2

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

If your needs are simple enough, built-in Django function-based views will do. When you outgrow those, DRF's complexity is often warranted.

But is DRFs complexity worth it compared to Ninja?

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

#10

Earlier quoted context omitted.

> Full support for Django and particularly it’s ORM (hard to do with FastAPI as the ORM is not yet async) I think you may have it backwards. Django's ORM isn't async yet [1], whereas FastAPI doesn't actually have an "included" ORM. However, the docs give an example of an async ORM [2], and SQLAlchemy also has async support [3]. --- [1] https://docs.djangoproject.com/en/4.0/topics/async/ : We’re still working on async…

The author of FastApi wrote an ORM too: https://github.com/tiangolo/sqlmodel I have not yet used it, but I think that’s the best approach now

Whats the deal with they large number of open issues an pull requests on FastAPI and SQLModel?

SQLModel 100 issues, 54 open PRs

FastAPI 903 issues, 448(!!) open PRs

I recently had to choose between Flask and FastAPI for a fresh project and went with Flask in the end, partly due to long term maintenance concerns with FastAPI.

Post reply on HN