Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Building a Python Web Application Using Flask and Neo4j

DZone's Guide to

Building a Python Web Application Using Flask and Neo4j

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

Flask, a popular Python web framework, has many tutorials available online which use an SQL database to store information about the website’s users and their activities.  While SQL is a great tool for storing information such as usernames and passwords, it is not so great at allowing you to find connections among your users for the purposes of enhancing your website’s social experience.

The quickstart Flask tutorial builds a microblog application using SQLite. In my tutorial, I walk through an expanded, Neo4j-powered version of this microblog application that uses py2neo, one of Neo4j’s Python drivers, to build social aspects into the application. This includes recommending similar users to the logged-in user, along with displaying similarities between two users when one user visits another user’s profile.

My microblog application consists of Users, Posts, and Tags modeled in Neo4j:

http://i.imgur.com/9Nuvbpz.png

With this graph model, it is easy to ask questions such as:

“What are the top tags of posts that I’ve liked?”

MATCH (me:User)-[:LIKED]->(post:Post)<-[:TAGGED]-(tag:Tag)
WHERE me.username = 'nicole'
RETURN tag.name, COUNT(*) AS count
ORDER BY count DESC
“Which user is most similar to me based on tags we’ve both posted about?”
MATCH (me:User)-[:PUBLISHED]->(:Post)<-[:TAGGED]-(tag:Tag), (other:User)-[:PUBLISHED]->(:Post)<-[:TAGGED]-(tag)
WHERE me.username = 'nicole' AND me <> other
WITH other,

    COLLECT(DISTINCT tag.name) AS tags,
    COUNT(DISTINCT tag) AS len

ORDER BY len DESC LIMIT 3
RETURN other.username AS similar_user, tags 
Links to the full walkthrough of the application and the complete code are below. If you would like a live walkthrough, be sure to register for my upcoming webinar on building a Python web application with Flask and Neo4j.

 

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. Our APIs verify, standardize, and correct the Big 4 + more – name, email, phone and global addresses – to ensure accurate delivery, prevent blacklisting and identify risks in real-time.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}