How to use the py2neo.neo4j function in py2neo

To help you get started, we’ve selected a few py2neo 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 technige / py2neo / test / neo4j_writebatch_set_labels.py View on Github external
def test_can_set_labels_on_preexisting_node():
    graph_db = neo4j.GraphDatabaseService()
    if not graph_db.supports_node_labels:
        return
    alice, = graph_db.create({"name": "Alice"})
    alice.add_labels("human", "female")
    batch = neo4j.WriteBatch(graph_db)
    batch.set_labels(alice, "mystery", "badger")
    batch.run()
    assert alice.get_labels() == {"mystery", "badger"}
github neo4j-contrib / neomodel / neomodel / core.py View on Github external
def create(cls, *props):
        category = cls.category()
        batch = CustomBatch(connection(), cls.index.name)
        deflated = [cls.deflate(p) for p in list(props)]
        # build batch
        for p in deflated:
            batch.create(neo4j.Node.abstract(**p))

        for i in range(0, len(deflated)):
            batch.create(neo4j.Relationship.abstract(category.__node__,
                    cls.relationship_type(), i, __instance__=True))
            cls._update_indexes(i, deflated[i], batch)
        results = batch.submit()
        return [cls.inflate(node) for node in results[:len(props)]]
github neo4j-contrib / neomodel / neomodel / util.py View on Github external
import re
from py2neo import neo4j
from .exception import UniqueProperty, DataInconsistencyError

camel_to_upper = lambda x: "_".join(word.upper() for word in re.split(r"([A-Z][0-9a-z]*)", x)[1::2])
upper_to_camel = lambda x: "".join(word.title() for word in x.split("_"))

# the default value "true;format=pretty" causes the server to lose
# individual status codes in batch responses
neo4j._headers[None] = [("X-Stream", "true")]


class CustomBatch(neo4j.WriteBatch):
    def __init__(self, graph, index_name, node='(unsaved)'):
        super(CustomBatch, self).__init__(graph)
        self.index_name = index_name
        self.node = node

    def submit(self):
        try:
            responses = self._execute()
            batch_responses = [neo4j.BatchResponse(r) for r in responses.json]
            if self._graph_db.neo4j_version < (1, 9):
                self._check_for_conflicts(responses, batch_responses, self._requests)
        except neo4j.BatchError as r:
            key = self._requests[r.id].body['key']
github octopus-platform / joern / libjoern / python / libjoern.py View on Github external
def _initJoernSteps(self):
        self.graphDb = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
   
        joernStepsDir = os.path.dirname(__file__) + '/joernsteps/'
        self.initCommand = self._createInitCommand(joernStepsDir)
github NCI-GDC / gdcdatamodel / data_model / visualization / neo2grapviz.py View on Github external
from py2neo import neo4j
from graphviz import Digraph

# host = "172.16.128.74"
host = "localhost"

query_string = "MATCH (a)-[r]->(b) RETURN DISTINCT (a._type) AS This, type(r) as To, (b._type) AS That"
db = neo4j.GraphDatabaseService("http://{host}:7474/db/data/".format(host=host))
result = neo4j.CypherQuery(db, query_string).execute()

dot = Digraph(comment="XML Generate Datamodel")
index = 0
for r in result:
    print r.values
    this, label, that = r.values

    if not this: 
        this = str(index)
        index += 1
    if not that: 
        that = str(index)
        index += 1

    dot.node(this)
github NCI-GDC / gdcdatamodel / data_model / visualization / get_properties_per_node.py View on Github external
from py2neo import neo4j
from pprint import pprint
import json

query_string = "MATCH (a) RETURN a"
db = neo4j.GraphDatabaseService()
results = neo4j.CypherQuery(db, query_string).execute()

mapping = {}

for result in results:
    node = result.values[0]
    _type = node['_type']

    if _type not in mapping: mapping[_type] = set()
    for key in node:
        mapping[_type].add(key)

mapping = {key: list(value) for key, value in mapping.iteritems()}

with open('node_properties.json', 'w') as fp:
    json.dump(mapping, fp)
github technige / py2neo / src / py2neo-examples / example1.py View on Github external
#!/usr/bin/env python

"""
Simple first example showing connection and traversal
"""

# Import Neo4j modules
from py2neo import neo4j

# Attach to the graph db instance
gdb = neo4j.GraphDatabaseService("http://localhost:7474/db/data")

# Obtain a link to the reference node of the db
ref_node = gdb.get_reference_node()

# Obtain a traverser instance relative to reference node
traverser = ref_node.traverse(order="depth_first", max_depth=2)

# Output all the paths from this traversal
for path in traverser.paths:
	print path
github NCI-GDC / gdcdatamodel / data_model / visualization / neo2grapviz.py View on Github external
from py2neo import neo4j
from graphviz import Digraph

# host = "172.16.128.74"
host = "localhost"

query_string = "MATCH (a)-[r]->(b) RETURN DISTINCT (a._type) AS This, type(r) as To, (b._type) AS That"
db = neo4j.GraphDatabaseService("http://{host}:7474/db/data/".format(host=host))
result = neo4j.CypherQuery(db, query_string).execute()

dot = Digraph(comment="XML Generate Datamodel")
index = 0
for r in result:
    print r.values
    this, label, that = r.values

    if not this: 
        this = str(index)
        index += 1
    if not that: 
        that = str(index)
        index += 1

    dot.node(this)
    dot.node(that)