Skip to content

Commit e2c7adb

Browse files
Add helper functions for reading from env variables
Co-authored-by: Rafal Skolasinski <[email protected]>
1 parent eda9331 commit e2c7adb

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
* Allow creating sessions of size `512GB`.
1515
* Allow passing additional parameters for the Neo4j driver connection to `GdsSessions.get_or_create(neo4j_driver_config={..})`
16+
* Add helper functions to create config objects from environment variables
17+
* `AuraApiCredentials::from_env`
18+
* `DbmsConnectionInfo::from_env`
1619

1720

1821
## Other changes

graphdatascience/session/dbms_connection_info.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
from dataclasses import dataclass
45
from typing import Optional
56

@@ -23,3 +24,20 @@ def auth(self) -> tuple[str, str]:
2324
A tuple containing the username and password.
2425
"""
2526
return self.username, self.password
27+
28+
@staticmethod
29+
def from_env() -> DbmsConnectionInfo:
30+
"""
31+
Create a DbmsConnectionInfo instance from environment variables.
32+
The environment variables are:
33+
- NEO4J_URI
34+
- NEO4J_USERNAME
35+
- NEO4J_PASSWORD
36+
- NEO4J_DATABASE
37+
"""
38+
uri = os.environ["NEO4J_URI"]
39+
username = os.environ.get("NEO4J_USERNAME", "neo4j")
40+
password = os.environ["NEO4J_PASSWORD"]
41+
database = os.environ.get("NEO4J_DATABASE")
42+
43+
return DbmsConnectionInfo(uri, username, password, database)

graphdatascience/session/gds_sessions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ class AuraAPICredentials:
3030
client_secret: str
3131
project_id: Optional[str] = None
3232

33+
@staticmethod
34+
def from_env() -> AuraAPICredentials:
35+
"""
36+
Create an AuraApi instance from environment variables.
37+
The environment variables are:
38+
- CLIENT_ID
39+
- CLIENT_SECRET
40+
- PROJECT_ID
41+
"""
42+
client_id = os.environ["CLIENT_ID"]
43+
client_secret = os.environ["CLIENT_SECRET"]
44+
project_id = os.environ.get("PROJECT_ID")
45+
46+
return AuraAPICredentials(client_id, client_secret, project_id)
47+
3348

3449
class GdsSessions:
3550
"""

0 commit comments

Comments
 (0)