Is it possible to connect to AuraDB with neomodel?
Asked Answered
K

2

7

Is it possible to connect to AuraDB with neomodel?

AuraDB connection URI is like neo4j+s://xxxx.databases.neo4j.io.
This is not contained user/password information.

However, connection config of neomodel is bolt and it is contained user/password information.
config.DATABASE_URL = 'bolt://neo4j:password@localhost:7687'

Kettle answered 28/2, 2022 at 4:47 Comment(1)
the equivalence of bolt in Aura is neo4j+s while localhost:7687 is similar to URI. Thus you can still connect from python neomodel to neo4j aura by using neoj4+s://neo4j:password@uri format.Fusillade
F
6

Connecting to neo4j Aura uses neo4j+s protocol so you need to use the provided uri by Aura.

Reference: https://neo4j.com/developer/python/#driver-configuration

In example below; you can set the database url by setting the userid and password along with the uri. It works for me so it should also work for you.

from neomodel import config

user = 'neo4j'
psw = 'awesome_password'
uri = 'awesome.databases.neo4j.io'
    
config.DATABASE_URL = 'neo4j+s://{}:{}@{}'.format(user, psw, uri)
print(config.DATABASE_URL)

Result: 

   neo4j+s://neo4j:[email protected]
Fusillade answered 1/3, 2022 at 16:13 Comment(0)
S
0

Another approach can be

user = os.environ['NEO4J_USERNAME']
pswd = os.environ['NEO4J_PASSWORD']
uri = os.environ['NEO4J_URI']

from neo4j import GraphDatabase
driver = GraphDatabase().driver(uri, auth=(user, pswd))
config.DRIVER = driver

from neomodel import db

db.set_connection(driver=driver)
db.cypher_query("RETURN 'Hello World' as message")

This way you can directly use the Auradb uri, without the need to extrapolate the username and password between the protocol and the url part of the URI.

Stearns answered 24/12, 2023 at 13:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.