Example to get graph object
from py2neo import Graph
@retry(stop_max_attempt_number=CONNECT_NEO4J_RETRIES, wait_fixed=(CONNECT_NEO4J_WAIT_SECS * 1000))
#NEO4J_AUTH=neo4j/deepak
def get_graph():
global NEO4J_URL,NEO4J_HOST,NEO4J_PORT,NEO4J_AUTH
# Connect to graph
creds = NEO4J_AUTH.split('/')
graph = Graph(user=creds[0], password=creds[1], host=NEO4J_HOST)
graph.run('match (t:Tweet) return COUNT(t)')
return graph
Create the cypher query and execute using graph.run() API. It has variable length parameters. 1st parameter is the Cypher query and subsequent parameters contain values for the query
Get the maximum tweet already added in the Neo4j DB
# Connect to graph
graph = get_graph()
max_id_query = 'match (u:User {screen_name:$screen_name})-[:POSTS]->(t:Tweet) return max(t.id) AS max_id'
res = graph.run(max_id_query, screen_name=screen_name)