Need advice about which tool to choose?Ask the StackShare community!

Django REST framework

1.9K
2K
+ 1
310
Graphene

100
143
+ 1
0
Add tool

Django REST framework vs Graphene: What are the differences?

Introduction

Django REST framework and Graphene are both popular tools used in building APIs in Python. While they serve a similar purpose, there are key differences between the two frameworks. In this article, we will explore and compare six major differences between Django REST framework and Graphene.

  1. Architecture: Django REST framework follows a traditional and proven MVC (Model-View-Controller) architecture, where the data models, views, and controllers are well defined. On the other hand, Graphene follows a GraphQL-based architecture, which allows clients to request only the data they need, resulting in more efficient and flexible API calls.

  2. Query Language: Django REST framework uses SQL-like queries to interact with the database and retrieve data. It provides a set of powerful ORM (Object-Relational Mapping) tools to simplify database operations. In contrast, Graphene utilizes GraphQL, which has its own query language focused on describing data requirements precisely.

  3. Schema Definition: In Django REST framework, the schema is defined implicitly based on the serializers and views. Serializers define the representation of data, and views handle the request-response flow. In Graphene, the schema is explicitly defined using a dedicated syntax. It allows developers to define types, fields, and resolvers, providing a more explicit and customizable approach to defining API schemas.

  4. API Flexibility: Django REST framework offers a comprehensive set of pre-built features for building APIs like authentication, pagination, serialization, etc. These features are readily available and can be easily integrated into an API. On the other hand, Graphene comes with a minimalistic approach and provides a lightweight framework for creating GraphQL APIs. While it doesn't provide all the pre-built features, it offers more flexibility to choose and integrate specific features as needed.

  5. Request and Response: Django REST framework primarily follows a request-response model, where a client sends a request to the server, and the server responds with the requested data. Graphene, being GraphQL-based, provides a more flexible request-response system. Clients can make multiple related queries in a single request, reducing the overhead of multiple requests.

  6. Community and Support: Django REST framework has been around for quite a long time and has a large and active community. It is widely adopted and has extensive documentation and community support. Graphene, being a relative newcomer focused on GraphQL, has a smaller community, but it is growing rapidly. Though the community support may not be as extensive as Django REST framework, it is evolving quickly and gaining popularity.

In summary, Django REST framework follows a traditional MVC architecture and leverages SQL-like queries, while Graphene adopts a GraphQL-based architecture and query language. Django REST framework offers more built-in features and provides a comprehensive framework for building APIs. On the other hand, Graphene provides more flexibility and efficiency with its GraphQL-based approach. Both frameworks have their strengths and are suitable for different use cases based on specific project requirements.

Advice on Django REST framework and Graphene
haydenlingle

I'm going to do an independent study with React for school, and I'm looking to build a full-stack application. I have lots of experience with react, but everything else I'd need is somewhat foreign to me. What I'm looking for is to provide a back-end for a React application.

I'm trying to find a back-end framework that can provide and integrate with almost everything I need (database, API, authentication). I will also need to be able to host everything eventually online rather than just locally on my computer. I don't want to use something that is just click-and-go: I want to learn a lot but find something that has much built in functionality, so I don't have to completely re-invent the wheel.

Does anyone else have experience with a stack you'd recommend that is a happy medium of helpful features while still requiring you to understand and implement the functionality yourself? Something well documented (e.g., it's easy to find documentation regarding putting all the pieces together) would be great.

Thanks in advance!

See more
Replies (7)
Marcelo Escobar
Recommends
on
RailsRails

Greate documentation, lot's of info on StackOverflow and it's easy to learn, a lot of things it's already implemented on the stack. It's based on Ruby which is stable and constantly evolving.

Ruby/Rails have a lot of gems(libraries) that will allow you to connect to many DB systems, implement JWT or use a library for authentication.

I have a lot of API's created in Rails that respond to website and mobile apps, and you can create your first one without a lot of stress, responding with JSON easily.

You can use VSCode has good support for ruby and you will have all syntax help etc, I use Atom but I don't have the syntax support, didn't found a good package for that.

See more
Recommends
on
Node.jsNode.js

The most popular stack that comes to mind for your case if MERN ( Mongo, Express, React and Node) I would use Nodejs + Express for backend. Easy to build dynamic and powerful REST APIs. For DB, it would be Mongo DB and front end can be React + Redux (for global state management). Plus NPM has a ton of packages for most cases. PS : Webstorm (free for students) or VS Code ( free for all) for IDE

See more
Alberto Mazaira
Recommends
on
Node.jsNode.jsRailsRails

I would take either Rails or Node for your problem.

Rails is a great framework: super complete in regards of testing frameworks, authentication libraries, great community support.... but I would say that the latest versions are a bit of a mess for newcomers, because of the way they manage assets: if the assets are served by the framework(Assets Pipeline) vs using Webpack .

If you are already familiar with React, Node is another great framework that will require a bit more effort on selecting the dependencies but for your use case seems a great candidate.

In regards of what you are commenting about learning during the process, both can be Dockerized pretty easy and you can spend some time digging on the lifecycle of putting it into production. Rails has a ridiculous easy way of deploying with Heroku avoiding any kind of work, but if you want to get your hands dirty you can deploy either of the frameworks on a Dockerized environment to any cloud provider you like. That part is really interesting too, and if you are interested on the Devops side, I would say that Node is a bit easier and more convenient(smaller image sizes and times to build) than Rails. All in all:

Rails pros: stable framework, great community support, great testing utilities. Rails cons: How they manage the assets lately(Assets Pipeline vs Webpack), dockerize the app.

Node pros: You are already familiar with Js, simple, easy to put in prod allowing to spend time in the Devops side. Node cons: Dependency management in Js environments is a pain in the ass

See more
Julien DeFrance
Principal Software Engineer at Tophatter · | 4 upvotes · 49.9K views
Recommends
on
RailsRails

Rails is an easy framework to pick up, and you'll get to love all of the magic it does for you. Some of that can be a little confusing at first but once you've got acquainted, this is part of the productivity Rails offers as opposed to other languages or frameworks that sometimes tend to require developers to waste a ton of valuable time setting up their own boilerplate when starting to work on a new project. More pragmatically, Rails is still extremely popular at both startups and at large companies, you can use it to power web applications, or backend APIs, and this will be extremely valuable on your resume. There also is a very large/rich set of libraries (called gems) that will allow you to focus on your actual project/product, rather than rebuilding what already exists. I'd recommend you go with the latest versions of Ruby (3.0) and Rails (6.1.1) so you are from the get-go learning them in their most current form.

See more

Node.js is great if you already know Javascript. If not, JS is pretty easy to learn. There are many resources and tutorials online for JS and Node. ASP.NET (Core) is a good option if you know C# or need high performance. Node.js isn't a complete framework like .NET, so you need to add Express or another HTTP server, and Database connectors etc.

See more
Rogério R. Alcântara
Recommends

Although not entirely confident, as I've never used Django and I've not used ASP.NET since 2.0, but given your requirements, at first thought, I'd go with Rails.

Yet, may I ask if have you considered some BAAS such as Firebase, Hasura and the like? Although I've admittedly suffered a bit with Firebase - I'm not totally sure if I've used it correctly, tho. But I've heard really awesome things about Hasura. This slant compairson shows some Firebase's alternatives that I've never heard. In your position, I would have a look.

Cheers.

See more
kristan-dev
Senior Solutions Analyst · | 8 upvotes · 343.6K views

My journey to developing REST APIs started with Flask Restful, and I've found it to be enough for the needs of my project back then. Now that I've started investing more time on personal projects, I've yet to decide if I should move to use Django for writing REST APIs. I often see job posts looking for Python+Django developers, but it's usually for full-stack developers. I'm primarily interested in Data Engineering, so most of my web projects are back end.

Should I continue with what I know (Flask) or move on to Django?

See more
Replies (1)
Rafael Torres
Technical Lead at 4Agile · | 9 upvotes · 334.1K views

If you want to be a Web developer with knowledge in another frontend and NoSql technology, maybe continue with Flask. However, if you want to create very fast solutions to grow up with a new business and merge these with data analysis and other tools, Django is the answer. Basically read more about the service architecture where you feel more comfortable, Microservice or Monolithic, but please will not married with any because they solve issues to different contexts.

See more
Saurav Pandit
Application Devloper at Bny Mellon · | 6 upvotes · 289K views

I have just started learning Python 3 weeks ago. I want to create a REST API using python. The API will be used to save form data in an Oracle database. The front end is using AngularJS 8 with Angular Material. In python, there are so many frameworks to develop REST APIs.

I am looking for some suggestions which REST framework to choose?

Here are some features I am looking for:

  • Easy integration and unit testing, like in Angular. We just want to run a command.

  • Code packaging, like in java maven project we can build and package. I am looking for something which I can push in as an artifact and deploy whole code as a package.

  • Support for swagger/ OpenAPI

  • Support for JSON Web Token

  • Support for test case coverage report

Framework can have features included or can be available by extension. Also, you can suggest a framework other than the ones I have mentioned.

See more
Replies (1)
Recommends
on
FlaskFlask
at

For starters flask provides a beautiful and easy way to create REST APIs. Also its supported by excellent beginner docs as well as a very active community. Another good thing with Flask is its widely available list of plugins which allow you to build as you go. Its also good in performance and can scale to a quite decent level. However, if you are sure your project is going to be fairly big, it would be better to start with Django as it provides a lot of features out of the box and is extremely stable in performance. Both these frameworks have support for Swagger, JWT, Coverage Report although you have to install plugins for them. Deploying both of these are fairly simple and there is huge documentation available. Django has one of the best documentations I have come across. I hope I was able to answer your queries.

See more
Decisions about Django REST framework and Graphene
Shiqi Lin
Software Developer at BigClarity · | 3 upvotes · 210.8K views

We will use Django to set up our backend and Django REST Framework (DRF) for our API creation. The easiness of performing development tasks (eg. user authentication, URL routing, and schema migration) attracts our attention. Also, Django with PostgreSQL provides many benefits: 1. Some data types in Django will only work with PostgreSQL; 2. Django offers django.contrib.postgres to operate on PostgreSQL; 3. Django supports many features of PostgreSQL. Moreover, Django is compatible with Redis.

See more
Max Khaikin
Dev Team Lead at BestDoctor · | 6 upvotes · 12K views

GraphQL is a great approach to API design that allows clients to get only stuff they need and facade some of the more macabre internal details of your servers.

Graphene-Django is also attractive in its simplicity, since you can expose everything you need in just a few lines of code, be done with web API and move on to the next task on your JIRA board.

However, Graphene, and especially Graphene-Django, did not work well for us, and this approach turned out to be a trap.

As Graphene-Django exposes everything even if you didn’t ask it to do so, a lot of time needs to be spent to make sure it doesn’t expose things you don’t need to expose. As it maps to your ORM, it also has access to all the reverse relations, m2m relations and similar stuff, and before you know it you can access data of other users from just about any query if you dig deep enough. On top of that, access management requires a lot of boilerplate.

Nested queries are not a great benefit, too, when you need to account for database access optimization and response size in general. Some pagination is possible, but it’s very convoluted to integrate into Graphene and further complicates queries for your client applications. Database optimization is also not pretty as there’re tons of contexts where a type can be accessed, and you need to account for lots of them.

That’s why we chose Django Rest Framework. When you account for all the necessities it requires less code and provides much more control over what, how, when and why your web APIs expose. Also, there's a lot of experienced developers on the market and it's easier to teach inexperienced ones.

See more
Ilya Lebedev

Python's GraphQL version – Graphene – has some critical disadvantages, that we found critical: - Lack of code optimisation. It is also hard to write optimized code because of graphene node API. - Nonsecure by default. By using reversed fks, you can get a lot of extra data. To stop this, we have to explicit exclude wrong fields, which seems to be error prone. - Nonflexible code structure. You can't make abstract graphene.ObjectType class, this limits us a lot.

These are some reasons, that make us move to Django REST framework .

See more
Get Advice from developers at your company using StackShare Enterprise. Sign up for StackShare Enterprise.
Learn More
Pros of Django REST framework
Pros of Graphene
  • 66
    Easy to use
  • 65
    Browsable api
  • 53
    Great documentation
  • 50
    Customizable
  • 42
    Fast development
  • 9
    Easy to use, customizable, pluggable, serializer
  • 8
    Python
  • 7
    Django ORM
  • 5
    FastSerialize
  • 3
    Less code
  • 2
    Easy implementation
  • 0
    Will replace RESTful interfaces
  • 0
    The future of API's

Sign up to add or upvote prosMake informed product decisions

Cons of Django REST framework
Cons of Graphene
  • 2
    Bad documentation
  • 2
    Reimplements Django functionality
  • 1
    No support for URL Namespaces
  • 0
    Bad CSRF handling
    Be the first to leave a con

    Sign up to add or upvote consMake informed product decisions

    - No public GitHub repository available -

    What is Django REST framework?

    It is a powerful and flexible toolkit that makes it easy to build Web APIs.

    What is Graphene?

    Graphene is a Python library for building GraphQL schemas/types fast and easily.

    Need advice about which tool to choose?Ask the StackShare community!

    What companies use Django REST framework?
    What companies use Graphene?
    See which teams inside your own company are using Django REST framework or Graphene.
    Sign up for StackShare EnterpriseLearn More

    Sign up to get full access to all the companiesMake informed product decisions

    What tools integrate with Django REST framework?
    What tools integrate with Graphene?

    Sign up to get full access to all the tool integrationsMake informed product decisions

    Blog Posts

    GitHubPythonReact+42
    49
    40722
    GitHubPythonNode.js+47
    54
    72306
    PythonDjangoDjango REST framework+3
    6
    5614
    What are some alternatives to Django REST framework and Graphene?
    Django
    Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
    Flask
    Flask is intended for getting started very quickly and was developed with best intentions in mind.
    Tastypie
    Tastypie is a webservice API framework for Django. It provides a convenient, yet powerful and highly customizable abstraction for creating REST-style interfaces.
    Swagger UI
    Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation and sandbox from a Swagger-compliant API
    Spring Boot
    Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
    See all alternatives