Skip to main content

Extension Flask for integration with neo4j graph database

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask2Neo4J-0.1a1.tar.gz (2.4 kB view hashes)

Uploaded Source

Built Distribution

Flask2Neo4J-0.1a1-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page