<commit_before>= Getting Started with Py2neo

Py2neo communicates with a Neo4j database via its RESTful HTTP interface. A {{{GraphDatabaseService}}} is exposed via the Neo4j server facility under a specific URI which, as described in the offical Neo4j documentation, is [[http://localhost:7474/db/data/]] within a default installation.

A {{{GraphDatabaseService}}} can be accessed in py2neo simply by creating an instance of the class with the same name. This class exists within the {{{py2neo.neo4j}}} module and requires the URI under which the service is exposed as an argument. The code below shows how to create such a connection:

{{{
from py2neo import neo4j
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
}}}

Once a connection has been established, nodes can be added to the graph using one of several methods. To create a single node, the {{{create_node}}} method can be used. If more than one node needs to be added, it is more efficient to use the batch creation method {{{create_nodes}}}. Finally, a Cypher {{{CREATE}}} statement can also be used. The code below illustrates these three node creation methods:

{{{
<<code lang="python">>
# create one node
a = graph_db.create_node({"name": "Alice"})

# create several nodes at once
b, c = graph_db.create_nodes(
    {"name": "Bob"},
    {"name": "Carol"}
}

# create a node using Cypher
from py2neo import cypher
query = "create d = {name: 'Dave'} return d"
data, metadata = cypher.execute(graph_db, query)
d = data[0][0]
<</code>>
}}}
<commit_msg>reset code macro<commit_after>= Getting Started with Py2neo

Py2neo communicates with a Neo4j database via its RESTful HTTP interface. A {{{GraphDatabaseService}}} is exposed via the Neo4j server facility under a specific URI which, as described in the offical Neo4j documentation, is [[http://localhost:7474/db/data/]] within a default installation.

A {{{GraphDatabaseService}}} can be accessed in py2neo simply by creating an instance of the class with the same name. This class exists within the {{{py2neo.neo4j}}} module and requires the URI under which the service is exposed as an argument. The code below shows how to create such a connection:

{{{
from py2neo import neo4j
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
}}}

Once a connection has been established, nodes can be added to the graph using one of several methods. To create a single node, the {{{create_node}}} method can be used. If more than one node needs to be added, it is more efficient to use the batch creation method {{{create_nodes}}}. Finally, a Cypher {{{CREATE}}} statement can also be used. The code below illustrates these three node creation methods:

{{{
# create one node
a = graph_db.create_node({"name": "Alice"})

# create several nodes at once
b, c = graph_db.create_nodes(
    {"name": "Bob"},
    {"name": "Carol"}
}

# create a node using Cypher
from py2neo import cypher
query = "create d = {name: 'Dave'} return d"
data, metadata = cypher.execute(graph_db, query)
d = data[0][0]
}}}

{'fraction_non_alphanumeric': 0.10052562417871222, 'fraction_numerical': 0.01445466491458607, 'mean_word_length': 4.822179732313575, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5611351', 'n_tokens_mistral': 886, 'n_tokens_neox': 847, 'n_words': 415}