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 set_path # Importing this module will add the project's home directory to sys.path
Added 'D:\Docs\- MY CODE\Brain Annex\BA-Win7' to sys.path
import os
import sys
import getpass
from neoaccess import NeoAccess
from brainannex.modules.neo_schema.neo_schema import NeoSchema
NeoAccess library¶NOTE: This tutorial is tested on version 4 of the Neo4j database, but will probably also work on the new version 5
# Save your credentials here (and skip the next cell!) - or use the prompts given by the next cell
#host = "" # EXAMPLES: bolt://123.456.789.012 OR neo4j://localhost
#password = ""
print("To create a database connection, enter the host IP, but leave out the port number: (EXAMPLES: bolt://1.2.3.4 OR neo4j://localhost )\n")
host = input("Enter host IP WITHOUT the port number. EXAMPLE: bolt://123.456.789.012 ")
host += ":7687" # EXAMPLE of host value: "bolt://123.456.789.012:7687"
password = getpass.getpass("Enter the database password:")
print(f"\n=> Will be using: host='{host}', username='neo4j', password=**********")
To create a database connection, enter the host IP, but leave out the port number: (EXAMPLES: bolt://1.2.3.4 OR neo4j://localhost )
=> Will be using: host='bolt://123.456.789.012:7687', username='neo4j', 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¶# db.empty_dbase() # ****** Recommended for use with test databases. 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", property_list=["name"])
(22390, 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")
