Skip to content

Extension Flask for integration with neo4j graph database

License

Notifications You must be signed in to change notification settings

ganggas95/flask2neo4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask2Neo4J

Extension Flask for integration with neo4j graph database

Installation

Using pip:

$ pip install flask2neo4j

Usage

Basic Step to usage this extension:

  1. Create Flask app instance:
import bcrypt
from py2neo import ogm
from flask import Flask, request
from flask2neo4j import Flask2Neo4J


app = Flask(__name__)

  1. Add NEO4J Config and Initialization Flask2Neo4j Extensions:

app.config["NEO4J_USERNAME"] = "neo4j"
app.config["NEO4J_PASSWORD"] = "neo4j"
app.config["NEO4J_URI"] = "bolt://localhost:7687"

flask2neo = Flask2Neo4J()

flask2neo.init_app(app)

  1. Create Model using Graph Object if using GraphObject
class Users(ogm.GraphObject):
    __primarykey__ = "id"

    id = ogm.Property()
    username = ogm.Property("username")
    password = ogm.Property("password")

    def create_password(self, password):
        self.password = str(bcrypt.encrypt(password))
    
    @property
    def is_exist(self):
        return flask2neo.graph.exists(self)

    def save(self):
        if self.is_exist:
            flask2neo.graph.merge(self)
            flask2neo.graph.push(self)
        else:
            flask2neo.graph.create(self)
  1. Define function register as flask request method POST
@app.route("/register", methods=["POST"])
def register():
    form = request.form
    user = Users()

    user.username = form['username']
    user.create_password(form['password'])
    user.save()
    return "User Created"

  1. Run flask app
if __name__ == '__main__':
    app.run(port=8500, debug=True)

Open your browser and type into url : http://localhost:8500

About

Extension Flask for integration with neo4j graph database

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages