How to use py2neo - 10 common examples

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 marksibrahim / knowledge_search / tools / neo4j_play / test_neo.py View on Github external
from py2neo import Graph, Node, Relationship

g = Graph()
tx = g.begin()
a = Node("Person", name="Alice")
tx.create(a)
b = Node("Person", name="Bob")
ab = Relationship(a, "KNOWS", b)
tx.create(ab)
tx.commit()
g.exists(ab)


"""
Sample Query
github technige / py2neo / test / test_repr.py View on Github external
def test_subgraph_repr(self):
        a = Node("Person", name="Alice")
        b = Node("Person", name="Bob")
        ab = Relationship(a, "TO", b)
        ba = Relationship(b, "FROM", a)
        s = ab | ba
        assert isinstance(s, Subgraph)
        r = repr(s)
        assert r.startswith("({")
        assert r.endswith("})")
        nodes, _, relationships = r[2:-2].partition("}, {")
        items = [item.strip() for item in nodes.split(",")]
        assert len(items) == 2
        for i, item in enumerate(items):
            assert re.match(r"\(:Person \{name: '(Alice|Bob)'\}\)", item)
        items = [item.strip() for item in relationships.split(",")]
        assert len(items) == 2
        for _ in items:
            assert re.match(r'\(.*\)-\[:(TO|FROM) \{\}\]->\(.*\)', repr(ab))
github technige / py2neo / test / neo4j_writebatch_delete_property.py View on Github external
def test_can_delete_property_on_node_in_same_batch():
    graph_db = neo4j.GraphDatabaseService()
    batch = neo4j.WriteBatch(graph_db)
    alice = batch.create({"name": "Alice", "age": 34})
    batch.delete_property(alice, "age")
    results = batch.submit()
    alice = results[batch.find(alice)]
    assert alice["name"] == "Alice"
    assert alice["age"] is None
github technige / py2neo / test / neo4j_writebatch_remove_label.py View on Github external
def test_can_add_labels_to_node_in_same_batch():
    graph_db = neo4j.GraphDatabaseService()
    batch = neo4j.WriteBatch(graph_db)
    alice = batch.create({"name": "Alice"})
    batch.add_labels(alice, "human", "female")
    batch.remove_label(alice, "female")
    results = batch.submit()
    alice = results[batch.find(alice)]
    assert alice.get_labels() == {"human"}
github technige / py2neo / test / neo4j_writebatch_create_path.py View on Github external
def test_can_create_path_with_existing_nodes():
    graph_db = neo4j.GraphDatabaseService()
    alice, bob = graph_db.create({"name": "Alice"}, {"name": "Bob"})
    batch = neo4j.WriteBatch(graph_db)
    batch.create_path(alice, "KNOWS", bob)
    results = batch.submit()
    path = results[0]
    assert len(path) == 1
    assert path.nodes[0] == alice
    assert path.relationships[0].type == "KNOWS"
    assert path.nodes[1] == bob
github technige / py2neo / test / neo4j_writebatch_set_properties.py View on Github external
def test_can_set_properties_on_node_in_same_batch():
    graph_db = neo4j.GraphDatabaseService()
    batch = neo4j.WriteBatch(graph_db)
    alice = batch.create({})
    batch.set_properties(alice, {"name": "Alice", "age": 34})
    results = batch.submit()
    alice = results[batch.find(alice)]
    assert alice["name"] == "Alice"
    assert alice["age"] == 34
github technige / py2neo / test / neo4j_writebatch_delete_property.py View on Github external
def test_can_delete_property_on_node_in_same_batch():
    graph_db = neo4j.GraphDatabaseService()
    batch = neo4j.WriteBatch(graph_db)
    alice = batch.create({"name": "Alice", "age": 34})
    batch.delete_property(alice, "age")
    results = batch.submit()
    alice = results[batch.find(alice)]
    assert alice["name"] == "Alice"
    assert alice["age"] is None
github technige / py2neo / test / neo4j_writebatch_create_path.py View on Github external
def test_can_create_path_with_existing_nodes():
    graph_db = neo4j.GraphDatabaseService()
    alice, bob = graph_db.create({"name": "Alice"}, {"name": "Bob"})
    batch = neo4j.WriteBatch(graph_db)
    batch.create_path(alice, "KNOWS", bob)
    results = batch.submit()
    path = results[0]
    assert len(path) == 1
    assert path.nodes[0] == alice
    assert path.relationships[0].type == "KNOWS"
    assert path.nodes[1] == bob
github technige / py2neo / test / neo4j_writebatch_add_labels.py View on Github external
def test_can_add_labels_to_node_in_same_batch():
    graph_db = neo4j.GraphDatabaseService()
    batch = neo4j.WriteBatch(graph_db)
    a = batch.create({"name": "Alice"})
    batch.add_labels(a, "human", "female")
    results = batch.submit()
    alice = results[batch.find(a)]
    assert alice.get_labels() == {"human", "female"}
github technige / py2neo / test / integration / test_relationship.py View on Github external
def test_relationship_creation_on_existing_node(graph):
    a = Node()
    graph.create(a)
    b = Node()
    r = Relationship(a, "TO", b)
    graph.create(r)
    assert r.graph is a.graph is graph
    assert r.identity is not None