The Story of gREST, A Graph-based Restful API Development Framework

3 minute read

More than a year ago, I was looking for a framework to build my services with which can support graph-based databases, namely Neo4j, and give me the freedom to customize it however I wanted. As my main language of choice was (and is) Python, I tried to look for frameworks written in Python. Many options came to mind, including Django, Flask, Tornado and many others. One of the biggest challenges I have faced was that none of them supported graph-based databases natively, meaning that they help the developer quickly get up and running with minimum amount of code. At that time I had to use one of the available Object-Graph Mappers (OGM) and would have to write my own set of functions to handle CRUD on database models. Such a simple thing for many other SQL and some NoSQL databases would lead to thousands of lines of code to handle creation, deletion and modification of nodes and their relationships.

After struggling to find such a framework, I decided to write my own set of functions as views to handle different endpoints I needed to get the job done.

As I have used and worked with Flask in other projects, I decided to go the path of using a micro-framework and develop what I needed and use available extensions. To quickly get up and running I used Flask-Classy which is an extension of the Flask framework that supports class-based views for each endpoint supporting various HTTP verbs. It has been deprecated and I have replaced it with Flask-Classful, which is a fork of the same project, but is actively developed.

My OGM of choice was (and still is) Neomodel, a very-well documented, feature-rich OGM for the Neo4j database. Neomodel had all the abstraction I wanted to quickly develop a set of models for nodes and their relations.

Mixing Flask, Flask-Classy, Neomodel allowed me to write a big class containing all the methods to expose views of my database models. I named the class generic_view, so that I can subclass it for each view and use it to serve each endpoint.

Everything was fine until I thought that I should pay back to the FOSS community. So I decided to extract that piece of code from the project and make it a separate project that can be used as a simple extension to the Flask framework.

So, I created gREST, a restful API development framework on top of Python, Flask, Neo4j and Neomodel. Its primary purpose is to ease development of restful APIs with little effort and minimum amount of code.

I used to make it a python package and distribute it on PYPI. I wrote unit-tests, a simple README and two simple examples to help developers know more about the workings of gREST.

I also used pytest for my unit-tests, Travis-CI for continuous integration and running tests, Coveralls for code coverage and Gitter for a place to answer developers’ questions. As I was concerned about the licensing of the project, I have released it under GPLv3 license and used the FOSSA license check services to know if there are licensing mismatches. The FOSSA team deserves a medal for its service.

It’s more than a year from the time I created my initial commit of the project and as per analytics, it has been downloaded more than 36,000 times and growing.

Download count of the gREST framework according to the Google BigQuery results on the the-psf:pypi dataset
Download count of the gREST framework according to the Google BigQuery results on the the-psf:pypi dataset

As I have twitted about it when I’ve made the project public, it has also been featured on the Neo4j’s blog.

Last but not least, I tried my best to fix bugs and make improvements to the initial idea of gREST, but it needs the help of the community to be further developed. I also hope that it continues to serve the community well. My next article would be a tutorial on making a simple restful API using gREST.

Update: At the time of writing this article, there was only 36k downloads, while now, June 24 2020, it’s almost 120k, according to PePy, which, I think, is impressive.