How to use the neo4j.GraphDatabase function in neo4j

To help you get started, we’ve selected a few neo4j examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aiidateam / aiida-core / other_stuff / preliminary_tests / aida_db / aidadb / sdk.py View on Github external
def getDb(dbName='db.tests/demo1'):

  if (os.path.isdir(dbName)):
    logging.info('GraphDb found, loading...')
    return GraphDatabase(dbName)
  else:
    logging.info('GraphDb not found, generating...')
    db = GraphDatabase(dbName)
    setUpDB(db)
    return db
github aiidateam / aiida-core / other_stuff / preliminary_tests / aida_db / aidadb / sdk.py View on Github external
def getDb(dbName='db.tests/demo1'):

  if (os.path.isdir(dbName)):
    logging.info('GraphDb found, loading...')
    return GraphDatabase(dbName)
  else:
    logging.info('GraphDb not found, generating...')
    db = GraphDatabase(dbName)
    setUpDB(db)
    return db
github RTXteam / RTX / code / ARAX / NodeSynonymizer / dump_kg2_synonym_field.py View on Github external
def _run_cypher_query(cypher_query: str, kg='KG2') -> List[Dict[str, any]]:
    # This function sends a cypher query to neo4j (either KG1 or KG2) and returns results
    rtxc = RTXConfiguration()
    if kg == 'KG2':
        rtxc.live = 'KG2'
    try:
        driver = GraphDatabase.driver(rtxc.neo4j_bolt, auth=(rtxc.neo4j_username, rtxc.neo4j_password))
        with driver.session() as session:
            print(f"Sending cypher query to {kg} neo4j")
            query_results = session.run(cypher_query).data()
            print(f"Got {len(query_results)} results back from neo4j")
        driver.close()
    except Exception:
        tb = traceback.format_exc()
        error_type, error, _ = sys.exc_info()
        print(f"Encountered an error interacting with {kg} neo4j. {tb}")
        return []
    else:
        return query_results
github sim51 / neo4j-fdw / neo4jPg / neo4jfdw.py View on Github external
log_to_postgres('The user parameter is required  and the default is "neo4j"', ERROR)
        self.user = options.get("user", "neo4j")

        if 'password' not in options:
            log_to_postgres('The password parameter is required for Neo4j', ERROR)
        self.password = options.get("password", "")

        if 'cypher' not in options:
            log_to_postgres('The cypher parameter is required', ERROR)
        self.cypher = options.get("cypher", "MATCH (n) RETURN n LIMIT 100")

        # Setting table columns
        self.columns = columns

        # Create a neo4j driver instance
        self.driver = GraphDatabase.driver( self.url, auth=(self.user, self.password))

        self.columns_stat = self.compute_columns_stat()
        self.table_stat = int(options.get("estimated_rows", -1))
        if(self.table_stat < 0):
            self.table_stat = self.compute_table_stat()
        log_to_postgres('Table estimated rows : ' + str(self.table_stat), DEBUG)
github graphistry / pygraphistry / graphistry / bolt_util.py View on Github external
def to_bolt_driver(driver=None):
    if driver is None:
        return None
    try:
        from neo4j import GraphDatabase, Driver
        if isinstance(driver, Driver):
            return driver
        return GraphDatabase.driver(**driver)
    except ImportError:
        raise BoltSupportModuleNotFound()
github renepickhardt / related-work.net / DataImport / DemoApp / demo_app_neo4j.py View on Github external
def init_globals():
    '''Restore global varibales on a running db'''
    global db
    global ROOT, PAPER, AUTHOR
    global author_idx, source_idx, label_idx, search_idx

    db = GraphDatabase(neo4j_db_folder)
    
    label_idx  = db.node.indexes.get('label_idx')
    source_idx = db.node.indexes.get('source_idx')
    author_idx = db.node.indexes.get('author_idx')
    search_idx = db.node.indexes.get('search_idx')
    
    AUTHOR = label_idx['label']['AUTHOR'].single
    PAPER  = label_idx['label']['PAPER'].single
    ROOT   = db.reference_node
github tovbinm / searchable-freebase / data / providers / neo4jdataProvider.py View on Github external
def __init__(self, params):
        self.dbPath = params["dbPath"]
        self.graphdb = neo4j.GraphDatabase(self.dbPath)         
        self.dataFiles = []
        dfs = params["dataFiles"]
        for df in dfs: self.dataFiles.append(dataUtils.getDataFileNameOnly(df))        
        self.cleanRegex = re.compile('[\!\*\?]+')
        self.pprintr = pprint.PrettyPrinter(indent=4)
github liqd / adhocracy3 / src / adhocracy.dbgraph / adhocracy / dbgraph / embeddedgraph.py View on Github external
@implementer(IGraph)
def graph_factory():
    """Utility to store the db graph conneciton object
    """
    settings = get_current_registry().settings
    connection_string = settings['graphdb_connection_string']
    import os
    os.environ['NEO4J_PYTHON_JVMARGS'] = '-Xms128M -Xmx512M'
    from neo4j import GraphDatabase
    db = GraphDatabase(connection_string)

    def close_db():
        """Make sure to always close the database
        """
        try:
            db.shutdown()
            print("db shut down")
        except NameError:
            print 'Could not shutdown Neo4j database.'

    atexit.register(close_db)

    return EmbeddedGraph(db)
github FSecureLABS / awspx / lib / graph / db.py View on Github external
def isavailable():
        try:
            GraphDatabase.driver(
                Neo4j.connection,
                auth=(Neo4j.username, Neo4j.password)
            ).session()

        except exceptions.ServiceUnavailable:
            return False
        return True