tutorial_neoaccess_1¶Note: if you need to clear out your test database, one of the cells below (currently commented out) will conveniently let you do it
import os
import sys
import getpass
from neoaccess import NeoAccess
from brainannex import NeoSchema
# In case of problems, try a sys.path.append(directory) , where directory is your project's root directory
NeoAccess library¶NOTE: This tutorial is tested on version 4.4 of the Neo4j database, but will probably also work on the new version 5 (NOT guaranteed, however...)
# Save your credentials here - or use the prompts given by the next cell
host = "" # EXAMPLES: bolt://123.456.789.012 OR neo4j://localhost
# (CAUTION: do NOT include the port number!)
password = ""
db = NeoAccess(host=host,
credentials=("neo4j", password), debug=False) # Notice the debug option being OFF
Connection to Neo4j database established.
print("Version of the Neo4j driver: ", db.version())
Version of the Neo4j driver: 4.4.11
NeoSchema library operations¶# CLEAR OUT THE DATABASE
#db.empty_dbase() # UNCOMMENT IF DESIRED ***************** WARNING: USE WITH CAUTION!!! ************************
NeoSchema.set_database(db)
# Create a "Car" Class node. Class nodes are part of the Schema
car_class_id, car_class_uri = NeoSchema.create_class(name="Car")
# Declare various Properties (data fields) for the "Car" Class
NeoSchema.add_properties_to_class(class_node = car_class_id, property_list = ['color', 'make'])
2
# Do a similar construction for a "Person" Class node - but this time do it all in just 1 step
NeoSchema.create_class_with_properties(name="Person", properties=["name"])
(43250, 'schema-4')
# Now add a relationship named "OWNED_BY", from the "Car" Class to the "Person" Class
NeoSchema.create_class_relationship(from_class="Car", to_class="Person", rel_name="OWNED_BY")
This is what we have so far:

# Having set up the Schema, time for some actual data! Add a Data Node for a "Car", and one for a "Person"
# Note that create_data_node() returns the internal database ID of the new node
car_id = NeoSchema.create_data_node(class_node="Car", properties={'color': 'white', 'make': 'Toyota'})
person_id = NeoSchema.create_data_node(class_node="Person", properties={'name': 'Julian'})
# Finally, add a relationship named "OWNED_BY", from the "Car" DATA node to the "Person" DATA node (as sanctioned in the Schema declared earlier)
NeoSchema.add_data_relationship(from_id=car_id, to_id=person_id, rel_name="OWNED_BY")
