Skip to content

Commit a31435d

Browse files
committed
Add ref docs for session classes
1 parent ffda15d commit a31435d

File tree

10 files changed

+108
-3
lines changed

10 files changed

+108
-3
lines changed

doc/sphinx/source/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ This API reference manual lists all available endpoints in the Neo4j Graph Data
3131
model/simple_rel_embedding_model
3232
misc
3333
server_version
34+
sessions/gds_sessions
35+
sessions/dbms_connection_info
36+
sessions/session_sizes
37+
sessions/gds_property_types
3438

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DbmsConnectionInfo
2+
----------------
3+
4+
.. autoclass:: graphdatascience.gds_session.dbms_connection_info.DbmsConnectionInfo
5+
:members:
6+
:inherited-members:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
GdsPropertyTypes
2+
----------------
3+
4+
.. autoclass:: graphdatascience.gds_session.schema.GdsPropertyTypes
5+
:members:
6+
:inherited-members:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
GDS Sessions
2+
----------------
3+
4+
5+
.. autoclass:: graphdatascience.gds_session.gds_sessions.GdsSessions
6+
:members:
7+
:inherited-members:
8+
9+
10+
.. autoclass:: graphdatascience.gds_session.gds_sessions.AuraAPICredentials
11+
:members:
12+
:inherited-members:
13+
14+
.. autoclass:: graphdatascience.gds_session.gds_sessions.SessionInfo
15+
:members:
16+
:inherited-members:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SessionSizes
2+
----------------
3+
4+
.. autoclass:: graphdatascience.gds_session.session_sizes.SessionSizes
5+
:members:
6+
:inherited-members:

examples/dev/gds-sessions.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
"from graphdatascience.session import GdsSessions, AuraAPICredentials\n",
255255
"\n",
256256
"# Create a new AuraSessions object\n",
257-
"sessions = GdsSessions(ds_connection=AuraAPICredentials(CLIENT_ID, CLIENT_SECRET))"
257+
"sessions = GdsSessions(api_credentials=AuraAPICredentials(CLIENT_ID, CLIENT_SECRET))"
258258
]
259259
},
260260
{

graphdatascience/session/dbms_connection_info.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@
66

77
@dataclass
88
class DbmsConnectionInfo:
9+
"""
10+
Represents the connection information for a DBMS.
11+
"""
12+
913
uri: str
1014
username: str
1115
password: str
1216

1317
def auth(self) -> Tuple[str, str]:
18+
"""
19+
Returns the username and password for authentication.
20+
21+
Returns:
22+
A tuple containing the username and password.
23+
"""
1424
return self.username, self.password

graphdatascience/session/gds_sessions.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
@dataclass
2020
class SessionInfo:
21+
"""
22+
Represents information about a session.
23+
"""
24+
2125
name: str
2226
size: str
2327
type: str
@@ -31,18 +35,38 @@ def from_specific_instance_details(cls, instance_details: InstanceSpecificDetail
3135

3236
@dataclass
3337
class AuraAPICredentials:
38+
"""
39+
Represents the credentials required for accessing the Aura API.
40+
41+
Attributes:
42+
client_id (str): The client ID for authentication.
43+
client_secret (str): The client secret for authentication.
44+
tenant (Optional[str]): The tenant for authentication. Needed if a client belongs to multiple tenants.
45+
"""
3446
client_id: str
3547
client_secret: str
3648
tenant: Optional[str] = None
3749

3850

3951
class GdsSessions:
52+
"""
53+
Primary API class for managing GDS sessions hosted in Neo4j Aura.
54+
"""
55+
4056
# Hardcoded neo4j user as sessions are always created with this user
4157
GDS_SESSION_USER = "neo4j"
4258

43-
def __init__(self, ds_connection: AuraAPICredentials) -> None:
59+
def __init__(self, api_credentials: AuraAPICredentials) -> None:
60+
"""
61+
Initializes a new instance of the GdsSessions class.
62+
63+
Args:
64+
api_credentials (AuraAPICredentials): The Aura API credentials used for establishing a connection.
65+
"""
4466
self._aura_api = AuraApi(
45-
tenant_id=ds_connection.tenant, client_id=ds_connection.client_id, client_secret=ds_connection.client_secret
67+
tenant_id=api_credentials.tenant,
68+
client_id=api_credentials.client_id,
69+
client_secret=api_credentials.client_secret,
4670
)
4771

4872
def get_or_create(
@@ -51,6 +75,19 @@ def get_or_create(
5175
size: SessionSizeByMemory,
5276
db_connection: DbmsConnectionInfo,
5377
) -> AuraGraphDataScience:
78+
"""
79+
Retrieves an existing session with the given session name and database connection,
80+
or creates a new session if one does not exist.
81+
82+
Args:
83+
session_name (str): The name of the session.
84+
size (SessionSizeByMemory): The size of the session specified by memory.
85+
db_connection (DbmsConnectionInfo): The database connection information.
86+
87+
Returns:
88+
AuraGraphDataScience: The session.
89+
"""
90+
5491
connected_instance = self._try_connect(session_name, db_connection)
5592
if connected_instance is not None:
5693
return connected_instance
@@ -101,6 +138,12 @@ def delete(self, session_name: str) -> bool:
101138
return False
102139

103140
def list(self) -> List[SessionInfo]:
141+
"""
142+
Retrieves the list of GDS sessions visible by the user asscociated by the given api-credentials.
143+
144+
Returns:
145+
A list of SessionInfo objects representing the GDS sessions.
146+
"""
104147
all_instances = self._aura_api.list_instances()
105148
instance_details = [
106149
self._aura_api.list_instance(instance_id=instance.id)

graphdatascience/session/schema.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66

77
class GdsPropertyTypes(Enum):
8+
"""
9+
Enumeration of supported property types inside the node/relationship schema of graphs to project into GDS sessions.
10+
"""
11+
812
LONG = "long"
913
DOUBLE = "double"
1014
LONG_ARRAY = "long[]"

graphdatascience/session/session_sizes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44

55
class SessionSizeByMemory(Enum):
6+
"""
7+
Enumeration representing session sizes.
8+
"""
9+
610
XS = "1GB"
711
S = "2GB"
812
SM = "4GB"
@@ -20,4 +24,10 @@ class SessionSizeByMemory(Enum):
2024
class SessionSizes:
2125
@staticmethod
2226
def by_memory() -> Type[SessionSizeByMemory]:
27+
"""
28+
Helper method to specify the memory size of a session.
29+
30+
Returns:
31+
Type[SessionSizeByMemory]: The SessionSizeByMemory class.
32+
"""
2333
return SessionSizeByMemory

0 commit comments

Comments
 (0)