Skip to content

Commit 8215175

Browse files
authored
Merge pull request #588 from FlorentinD/gds-session-ref-docs
Add ref docs for GDS sessions
2 parents ffda15d + 8dbbc41 commit 8215175

File tree

12 files changed

+125
-6
lines changed

12 files changed

+125
-6
lines changed

doc/sphinx/README.adoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ To build the html content, do this:
77

88
1. Set working directory to the root of this repository.
99
2. Install sphinx into your venv: `pip install sphinx`
10-
3. Build the HTML: `(cd doc/sphinx && make html)`
11-
4. Serve the HTML: `(cd doc/sphinx/build/ && python -m http.server 8000)`
12-
5. Go to `localhost:8000` in your web browser.
10+
3. Run `./scripts/render_api_docs`
11+
4. Go to `localhost:8000` in your web browser.
1312
1413
In order to make changes, iterate on steps 3-5 above.
1514

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.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.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.session.gds_sessions.GdsSessions
6+
:members:
7+
:inherited-members:
8+
9+
10+
.. autoclass:: graphdatascience.session.gds_sessions.AuraAPICredentials
11+
:members:
12+
:inherited-members:
13+
14+
.. autoclass:: graphdatascience.session.gds_sessions.SessionInfo
15+
:members:
16+
:inherited-members:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SessionSizes
2+
----------------
3+
4+
.. autoclass:: graphdatascience.session.session_sizes.SessionSizeByMemory
5+
:members:
6+
:inherited-members:
7+
8+
.. autoclass:: graphdatascience.session.session_sizes.SessionSizes
9+
:members:
10+
: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 Neo4j DBMS, such as an AuraDB instance.
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: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818

1919
@dataclass
2020
class SessionInfo:
21+
"""
22+
Represents information about a session.
23+
24+
Attributes:
25+
name (str): The name of the session.
26+
size (str): The size of the session.
27+
"""
28+
2129
name: str
2230
size: str
2331
type: str
@@ -31,18 +39,39 @@ def from_specific_instance_details(cls, instance_details: InstanceSpecificDetail
3139

3240
@dataclass
3341
class AuraAPICredentials:
42+
"""
43+
Represents the credentials required for accessing the Aura API.
44+
45+
Attributes:
46+
client_id (str): The client ID for authentication.
47+
client_secret (str): The client secret for authentication.
48+
tenant (Optional[str]): The tenant for authentication. Needed if a client belongs to multiple tenants.
49+
"""
50+
3451
client_id: str
3552
client_secret: str
3653
tenant: Optional[str] = None
3754

3855

3956
class GdsSessions:
57+
"""
58+
Primary API class for managing GDS sessions hosted in Neo4j Aura.
59+
"""
60+
4061
# Hardcoded neo4j user as sessions are always created with this user
4162
GDS_SESSION_USER = "neo4j"
4263

43-
def __init__(self, ds_connection: AuraAPICredentials) -> None:
64+
def __init__(self, api_credentials: AuraAPICredentials) -> None:
65+
"""
66+
Initializes a new instance of the GdsSessions class.
67+
68+
Args:
69+
api_credentials (AuraAPICredentials): The Aura API credentials used for establishing a connection.
70+
"""
4471
self._aura_api = AuraApi(
45-
tenant_id=ds_connection.tenant, client_id=ds_connection.client_id, client_secret=ds_connection.client_secret
72+
tenant_id=api_credentials.tenant,
73+
client_id=api_credentials.client_id,
74+
client_secret=api_credentials.client_secret,
4675
)
4776

4877
def get_or_create(
@@ -51,6 +80,19 @@ def get_or_create(
5180
size: SessionSizeByMemory,
5281
db_connection: DbmsConnectionInfo,
5382
) -> AuraGraphDataScience:
83+
"""
84+
Retrieves an existing session with the given session name and database connection,
85+
or creates a new session if one does not exist.
86+
87+
Args:
88+
session_name (str): The name of the session.
89+
size (SessionSizeByMemory): The size of the session specified by memory.
90+
db_connection (DbmsConnectionInfo): The database connection information.
91+
92+
Returns:
93+
AuraGraphDataScience: The session.
94+
"""
95+
5496
connected_instance = self._try_connect(session_name, db_connection)
5597
if connected_instance is not None:
5698
return connected_instance
@@ -101,6 +143,12 @@ def delete(self, session_name: str) -> bool:
101143
return False
102144

103145
def list(self) -> List[SessionInfo]:
146+
"""
147+
Retrieves the list of GDS sessions visible by the user asscociated by the given api-credentials.
148+
149+
Returns:
150+
A list of SessionInfo objects representing the GDS sessions.
151+
"""
104152
all_instances = self._aura_api.list_instances()
105153
instance_details = [
106154
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[]"

0 commit comments

Comments
 (0)