NebulaGraph Python Client 5.3.0
Loading...
Searching...
No Matches
session_conf.py
1# Copyright 2025 vesoft-inc
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from typing import Optional
16
17from nebulagraph_python.client import NebulaBaseExecutor
18
19
20def get_home_graph_name(cli: NebulaBaseExecutor) -> str:
21 """Get the home graph name of the current session."""
22 rec = cli.execute_py("SHOW CURRENT_SESSION").one()
23 try:
24 res = rec["graph"].cast(str) # For version >= 5.1
25 except KeyError:
26 res = rec["home_graph_name"].cast(str) # For version == 5.0
27 return res
28
29
30def get_graph_type_name(
31 cli: NebulaBaseExecutor, graph_name: Optional[str] = None
32) -> str:
33 """Get the graph type of the current graph.
34
35 Args:
36 cli: The client to use for the query.
37 graph_name: The name of the graph to get the type of. Default to the home graph of the current session.
38 """
39 return (
40 cli.execute_py(f"""DESCRIBE GRAPH `{graph_name or get_home_graph_name(cli)}`""")
41 .one()["graph_type_name"]
42 .cast(str)
43 )