Live data from Hacker News

Django Ninja – Fast Django REST Framework for Building APIs

github.com

11–20 of 35 posts

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

#11

Earlier quoted context omitted.

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.

There was a recent discussion about it here including a reply from the FastAPI creator explaining the situation:

https://news.ycombinator.com/item?id=29471609

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

#12

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…

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.

This isn’t exactly true. The Django ORM can be used with care in the async views found in FastAPI and Django (see sync_to_async and run_in_threadpool helpers).

Plans exist to make the Django Queryset async, so it’ll be exciting when that day comes!

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

#13
post #6

Earlier quoted context omitted.

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?

DRF was about as good as it got for automatic schema generation and data validation before python static type hints made things like pydantic possible. It also sets up good defaults for stuff like query parameter-based filtering, pagination, and resource relationships (it supports HATOAS by default).

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

#14
post #12

Earlier quoted context omitted.

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.

This isn’t exactly true. The Django ORM can be used with care in the async views found in FastAPI and Django (see sync_to_async and run_in_threadpool helpers). Plans exist to make the Django Queryset async, so it’ll be exciting when that day comes!

Very true, and I have been following this pull request implementing Async Queryset with interest:

https://github.com/django/django/pull/14843

So far they are only going down the the queryset level, it then uses a thread pool for the db connector, next job would be to support async db connections.

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

#16
post #6

Earlier quoted context omitted.

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?

DRF isn't necessarily complex, you can still use its generic views.

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

#17

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…

Yes but it doesn't have auto generated documentation, API testing UI, standardize output format, non-cookie auth, pagination, throttling...

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

#18

Earlier quoted context omitted.

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.

Having given SqlModel a very proper go a few months back, I have to say that it's not worth using it just yet. There are too many outstanding issues and the documentation is also incomplete. Maybe in a year's time, the situation could be different.

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

#19
post #2

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

I like DRF, especially when I have to come back after some time or get in a new project and looking for where things happen. But ya, boilerplate city. It really feels wrong typing out the serializers, the views, repeating the same steps over and over. It's too much.

I'm excited to try this out, been looking at FastAPI.

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

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

> If your needs are simple enough, built-in Django function-based views will do

This is the bit I find not really true.

My needs are simple (10-20 basic get/post/put/delete APIs, many at the business logic layer than true REST) but I still would really like the OpenAPI docs, auto-generated schema definitions, etc etc. If I can get that with just some simple decorators on my existing views and pydantic models for the inputs and outputs .... that would be awesome.

Post reply on HN