Skip to content

Commit 13442a2

Browse files
[Python] Example with dotenv for Aura.
1 parent 0e35e1e commit 13442a2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

python-manual/modules/ROOT/pages/connect.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,30 @@ Share them across threads (but not across processes) and use xref:transactions#i
3131
If you want to alter a `Driver` configuration, you will need to create a new object.
3232

3333

34+
== Connect to an Aura instance
35+
36+
When you create an <<Aura>> instance, you may download a text file containing the connection information to the database.
37+
The file has a name of the form `Neo4j-a0a2fa1d-Created-2023-11-06.txt`.
38+
39+
To connect to such an instance, you may either use the URI, username, and password explicitly in your application, or load the content of the connection file in the environment with `dotenv.load_dotenv()` and populate your local variables with `os.getenv()`.
40+
This requires the package link:https://pypi.org/project/python-dotenv/[`python-dotenv`] to be installed.
41+
42+
[source,python,role=test-skip]
43+
----
44+
import dotenv
45+
import os
46+
from neo4j import GraphDatabase
47+
48+
dotenv.load_dotenv('Neo4j-a0a2fa1d-Created-2023-11-06.txt')
49+
50+
URI = os.getenv("NEO4J_URI")
51+
AUTH = (os.getenv("NEO4J_USERNAME"), os.getenv("NEO4J_PASSWORD"))
52+
53+
with GraphDatabase.driver(URI, auth=AUTH) as driver:
54+
driver.verify_connectivity()
55+
----
56+
57+
3458
== Close connections
3559

3660
Always close `Driver` objects to free up all allocated resources, even upon unsuccessful connection or runtime errors.

0 commit comments

Comments
 (0)