Created
August 20, 2025 22:33
-
-
Save jalakoo/9e0ff836bc75e1a2b9945baf2eede4c4 to your computer and use it in GitHub Desktop.
Neo4j Intro To Python Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from neo4j import GraphDatabase | |
| # Read-only credentials | |
| URI = "neo4j+s://demo.neo4jlabs.com" | |
| USERNAME = "goodreads" | |
| PASSWORD = "goodreads" | |
| DATABASE = "goodreads" | |
| def main(query, params): | |
| with GraphDatabase.driver(URI, auth=(USERNAME, PASSWORD)) as driver: | |
| records, summary, keys = driver.execute_query( | |
| query, | |
| parameters_ = params, | |
| database_ = DATABASE | |
| ) | |
| return [record.data() for record in records] | |
| if __name__ == "__main__": | |
| import json | |
| query = """ | |
| MERGE (b:Book {title: $title}) | |
| RETURN b.title as title | |
| LIMIT $limit | |
| """ | |
| params = { | |
| "title": "The Great Gatsby", | |
| "limit": 10 | |
| } | |
| result = main(query, params) | |
| print(json.dumps(result, indent=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment