Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neo4j Test Project

This project demonstrates how to connect to and interact with Neo4j using Python.

Prerequisites

  1. Neo4j Desktop installed and running
  2. Python 3.7+ installed
  3. A Neo4j database created in Neo4j Desktop

Setup Instructions

1. Start Neo4j Desktop

  1. Open Neo4j Desktop
  2. Create a new project (or use an existing one)
  3. Create a new database or start an existing one
  4. Note your database credentials:
    • URI: Usually bolt://localhost:7687 (check in database details)
    • Username: Default is neo4j
    • Password: The password you set when creating the database

2. Install Python Dependencies

Open a terminal in this directory and run:

pip install -r requirements.txt

Or install directly:

pip install neo4j

3. Configure Connection

Open neo4j_test.py and update the connection settings in the main() function:

URI = "bolt://localhost:7687"  # Your Neo4j URI
USER = "neo4j"                  # Your username
PASSWORD = "your_password"      # Your password

4. Run the Test Script

python neo4j_test.py

What the Script Does

The test script performs the following operations:

  1. Connection Test: Verifies that it can connect to your Neo4j database
  2. Create Sample Data:
    • Creates 3 Person nodes (Alice, Bob, Charlie)
    • Creates 2 Company nodes (ACME Corp, TechCo)
    • Creates relationships (WORKS_AT, KNOWS)
  3. Query Data: Retrieves and displays the created data
  4. Count Nodes: Shows the total number of nodes in the database

Expected Output

=== Neo4j Connection Test ===

INFO:__main__:Connected to Neo4j at bolt://localhost:7687
INFO:__main__:✓ Connection successful!

Cleaning existing data...
INFO:__main__:✓ Cleaned up all test data

Creating sample data...
INFO:__main__:✓ Created Person nodes
INFO:__main__:✓ Created Company nodes
INFO:__main__:✓ Created relationships

Querying data...

--- All Persons ---
  Alice, Age: 30
  Bob, Age: 25
  Charlie, Age: 35

--- Employment Relationships ---
  Alice works at ACME Corp
  Bob works at TechCo

--- Friendships ---
  Alice knows Bob

INFO:__main__:✓ Total nodes in database: 5

=== Test completed successfully! ===

Troubleshooting

Connection Errors

If you see connection errors:

  1. Verify Neo4j is running: Check Neo4j Desktop to ensure your database is started
  2. Check the URI: In Neo4j Desktop, click on your database and verify the Bolt URL
  3. Verify credentials: Make sure username and password are correct
  4. Check port: Default is 7687, but verify in Neo4j Desktop settings

Import Errors

If you see ModuleNotFoundError: No module named 'neo4j':

pip install neo4j

Viewing Data in Neo4j Browser

After running the script, you can view the data in Neo4j Browser:

  1. In Neo4j Desktop, click "Open" on your database
  2. Run this Cypher query to see everything:
MATCH (n) RETURN n

Or try these specific queries:

// View all persons
MATCH (p:Person) RETURN p

// View relationships
MATCH (p:Person)-[r]->(c:Company) RETURN p, r, c

// View the graph
MATCH (n)-[r]->(m) RETURN n, r, m

Clean Up

The script includes a cleanup function that removes all test data. By default, it runs at the start to ensure a clean slate. If you want to also clean up at the end, uncomment these lines in neo4j_test.py:

# logger.info("\nCleaning up...")
# neo4j_test.cleanup()

Next Steps

  • Modify the script to create your own data models
  • Explore more complex Cypher queries
  • Try the Neo4j Browser for visual exploration
  • Check out the Neo4j Python Driver documentation

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages