Performing CRUD Operations Programmatically
Execute Cypher queries from your application to create, read, update, and delete graph data dynamically.
CRUD from Your Application
When building applications, you'll often need to interact with your Neo4j database programmatically. This means writing code that sends Cypher queries to create, read, update, and delete data.
These fundamental operations are often referred to as CRUD:
- Create: Adding new data (nodes, relationships).
- Read: Retrieving existing data.
- Update: Modifying existing data.
- Delete: Removing data.
Connecting to Neo4j (Review)
Before performing any CRUD operations, your application needs to connect to the Neo4j database. As we learned previously, the official Neo4j Python Driver simplifies this.
You'll use a GraphDatabase.driver object to manage connections and then create a session to execute queries.
from neo4j import GraphDatabase
URI = "bolt://localhost:7687"
AUTH = ("neo4j", "password") # Use your credentials
def main():
driver = GraphDatabase.driver(URI, auth=AUTH)
with driver.session() as session:
# Your Cypher queries will go here
print("Connected to Neo4j!")
driver.close()
if __name__ == "__main__":
main()All lessons in this course
- Connecting with the Python Driver
- Performing CRUD Operations Programmatically
- Handling Transactions and Sessions
- Connection Pooling and Error Handling