Advise on REST API for django

65 views
Skip to first unread message

Ravi

unread,
Mar 8, 2014, 12:50:15 PM3/8/14
to pym...@googlegroups.com
Hi

I would like to know the difference between the two better know REST API projects for django: tastypie and django-rest-framework. Are there better ones? On the surface, they look similar. 

The problem we are trying to solve is to create an Android / IPhone app  for our site http://www.reedwith.us that will interact with a REST based webservice.  The queries are not simple table lookups but "complex" functions that checks if a user has permission to access the data. We also want to ensure that the product developed using the API will scale to many user requests.  Any suggestion is welcome. 

Thanks,

Ravi

Peter J. Farrell

unread,
Mar 10, 2014, 5:51:14 PM3/10/14
to pym...@googlegroups.com
Ravi said the following on 03/08/2014 11:50 AM:
Hi

I would like to know the difference between the two better know REST API projects for django: tastypie and django-rest-framework. Are there better ones? On the surface, they look similar. 

The problem we are trying to solve is to create an Android / IPhone app  for our site http://www.reedwith.us that will interact with a REST based webservice.  The queries are not simple table lookups but "complex" functions that checks if a user has permission to access the data. We also want to ensure that the product developed using the API will scale to many user requests.  Any suggestion is welcome.
We were deciding at work last Fall on API framework and decided to use tastypie with Django.  I think at the time, django-rest-framework was not well maintained and I think that has changed since we made that decision.

One thing we liked about TastyPie was that it implemented filters in the style of Django ORM filters (ex. ?age__gt=30). In Django-Rest, you have to write custom filters for each model.

Also, Django-Rest was more like Django's class based views and TastyPie is not.  TastyPie seemed to have more sensible defaults.  Also, TastyPie is written by the same folks that built Django-Haystack which is awesome too.  Also, the doco for TastyPie seems more through and complete.

I don't think you can go wrong with either choice.  But TastyPie won without much thought.
-- 
Peter J. Farrell
Principal Technologist - Maestro Publishing, LLC
http://blog.maestropublishing.com
Identi.ca / Twitter: @maestrofjp

* Learn about VSRE. I prioritize emails with VSRE in the subject!  http://vsre.info/
* Please do not send me Microsoft Office/Apple iWork documents. Send OpenDocument instead! http://fsf.org/campaigns/opendocument/

Adam Ness

unread,
Mar 11, 2014, 12:38:29 PM3/11/14
to pym...@googlegroups.com
I worked with Django-rest-framework last spring, and there were some
issues with it in terms of flexibility. It's strongly centered around
the django orm and class-based views, which can make it very quick to
integrate, but limits its flexibility for certain tasks. It is very
nice though in terms of generating self-documenting interfaces, and
providing some very good testing interfaces as well. Tastypie is a
lot more flexible in terms of how you define your REST endpoints, and
seems to be better maintained. It all kind of depends on what you're
doing, but I think that I'd generally fall more on the tastypie side.
Adam Ness
> --
> Meetings Schedule / RVSP on our Meetup at http://python.mn
> ---
> You received this message because you are subscribed to the Google Groups
> "PyMNtos" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pymntos+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ravi

unread,
Mar 11, 2014, 9:18:09 PM3/11/14
to pym...@googlegroups.com
I already have a django project with all view functions currently responding with HTML. Based on the your feedback, I think django-rest-framework will be a good choice for us. @Adam: you indicated that the django-rest-framework has some limits in the flexibility.  Can you give me more details?

Ravi

Peter J. Farrell

unread,
Mar 11, 2014, 9:36:49 PM3/11/14
to pym...@googlegroups.com
Ravi said the following on 03/11/2014 08:18 PM:
Ravi, is your API returning JSON/XML data or pre-rendered HTML chunks?

The client should send an `accept` header with the appropriate MIME type
like application/json or text/html. If the endpoint doesn't support the
requested MIME type, it should return a HTTP 406 - Not Acceptable
response because the API doesn't support the requested data format.

In Django Rest Framework, you need to write a custom serializer for each
object you are returning:

http://www.django-rest-framework.org/api-guide/serializers

Once you have an object serializer, then you can past it to a built-in
parser (like JSON, XML, etc) which marshals data between the target
format and native Python.

Whereas Tastypie uses meta data from your object and some configuration
to "create" custom serializers and parsers for you automatically:

http://django-tastypie.readthedocs.org/en/latest/serialization.html

I found that Django Rest Framework just a lot of extra typing for extra
power (unless you want that control). I've found this part to be the
most tedious part of Django Rest and makes TastyPie a lot more easy to
use especially if you have a large model.

So if you have to reuse stuff in your views, you might look at the
Cookbook entry in using API resources in regular Django Views:

http://django-tastypie.readthedocs.org/en/latest/cookbook.html#using-your-resource-in-regular-views

Derek Anderson

unread,
Apr 8, 2014, 10:30:05 AM4/8/14
to pym...@googlegroups.com
Ravi, 

Your findings would make for a great presentation at this months Django meetup! We have plenty of seats available for anyone interested as well.

Thanks!

Derek

Reply all
Reply to author
Forward
0 new messages