def bolt_driver(target, auth): try: driver = GraphDatabase.bolt_driver(target, auth=auth) try: yield driver finally: driver.close() except ServiceUnavailable as error: if isinstance(error.__cause__, BoltHandshakeError): pytest.skip(error.args[0])
def process_to_df(self, *args, **options): """Neo4j Handling Logic""" if not options["password"]: options["password"] = getpass(prompt="Password: "******"bolt://%s:%d" % (options["host"], options["port"]) auth = (options["user"], options["password"]) with GraphDatabase.bolt_driver(uri, auth=auth) as driver: with driver.session() as session: records = session.run(options["query"]) return DataFrame([r.values() for r in records], columns=records.keys())
def bolt_driver(target, auth): driver = GraphDatabase.bolt_driver(target, auth=auth) try: yield driver finally: driver.close()
''' This Python script will create nodes in Neo4j that represent cities with more than 100,000 population, from cities.json. The cities.json file must exist in the same directory as this Python script. ''' from neo4j import GraphDatabase import json import os script_dir = os.path.dirname(os.path.realpath(__file__)) print(script_dir) n4j = GraphDatabase.bolt_driver('localhost', auth=('neo4j', 'test')) session = n4j.session() city_list = '' with open('{0}\\cities.json'.format(script_dir)) as cities: city_list = json.loads(cities.read()) # Create nodes for each city in the United States for city in city_list: print(city) query = 'MERGE (n:city {{ name: "{0}" }})'.format(city['city']) session.run(query)
''' This Python script demonstrates how to retrieve results from Neo4j database queries. ''' from neo4j import GraphDatabase as n4j bolt = n4j.bolt_driver('localhost', auth=('neo4j', 'test')) sess = bolt.session() result = sess.run('MATCH (c:city)-[r:EXISTS_IN]->(s:state) RETURN c,r,s;') [print(city) for city in result.values()]