嬴图Python驱动提供一系列数据结构,用于应用与图数据库的交互。
所有数据结构均支持getter方法获取属性,以及setter方法设定属性值。
Node
Node
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
uuid |
int | / | 点_uuid |
id |
str | / | 点_id |
schema |
str | / | 点所属的Schema名称 |
values |
Dict[str,any] | / | 点属性键值对 |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.gql("MATCH (n) RETURN n LIMIT 5", requestConfig)
nodes = response.alias("n").asNodes()
print("ID of the first node:", nodes[0].getID())
print("Name of the first node:", nodes[0].get("name"))
ID of the first node: ULTIPA800000000000004B
Name of the first node: Claire89
Edge
Edge
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
uuid |
int | / | 边_uuid |
fromUuid |
int | / | 边起点的_uuid |
toUuid |
int | / | 边终点的_uuid |
fromId |
str | / | 边起点的_id |
toId |
str | / | 边终点的_id |
schema |
str | / | 边所属的Schema名称 |
values |
Dict[str,any] | / | 边属性键值对 |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.gql("MATCH ()-[e]->() RETURN e LIMIT 3", requestConfig)
edges = response.alias("e").asEdges()
for edge in edges:
print(edge.getValues())
{'toUuid': 13, 'uuid': 110, 'fromUuid': 7}
{'toUuid': 1032, 'uuid': 1391, 'fromUuid': 7, 'timestamp': 1537331913, 'datetime': '2018-09-19 12:38:33'}
{'toUuid': 1005, 'uuid': 1390, 'fromUuid': 7, 'timestamp': 1544118960, 'datetime': '2018-12-07 01:56:00'}
Path
Path
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
nodeUUids |
List[int] | / | 路径中点的_uuid 列表 |
edgeUuids |
List[int] | / | 路径中边的_uuid 列表 |
nodes |
Dict[int, Node] | {} |
路径中点的字典,其中键是点的_uuid ,值是相应的点 |
edges |
Dict[int, Edge] | {} |
路径中边的字典,其中键是边的_uuid ,值是相应的边 |
Path
对象支持的方法:
方法 |
返回值 |
描述 |
---|---|---|
length() |
int | 获取路径长度,即路径中的边数量 |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.gql("MATCH p = ()-[]-()-[]-() RETURN p LIMIT 3", requestConfig)
graph = response.alias("p").asGraph()
print("Nodes in each returned path:")
paths = graph.paths
for path in paths:
print(path.nodeUuids)
Nodes in each returned path:
[6196955286285058052, 7998395137233256457, 8214567919347040275]
[6196955286285058052, 7998395137233256457, 8214567919347040275]
[6196955286285058052, 7998395137233256457, 5764609722057490441]
Graph
Graph
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
paths |
List[Path ] |
/ | 返回的路径列表 |
nodes |
Dict[int, Node] | {} |
图中点的字典,其中键是点的_uuid ,值是相应的点 |
edges |
Dict[int, Edge] | {} |
图中边的字典,其中键是边的_uuid ,值是相应的边 |
Graph
对象支持的方法:
方法 |
参数 |
返回值 |
描述 |
---|---|---|---|
addNode() |
node: Node |
/ | 向nodes 中新增一个点 |
addEdge() |
edge: Edge |
/ | 向edges 中新增一条边 |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.gql("MATCH p = ()-[]-()-[]-() RETURN p LIMIT 3", requestConfig)
graph = response.alias("p").asGraph()
print("Nodes in each returned path:")
paths = graph.paths
for path in paths:
print(path.nodeUuids)
print("----------")
print("Nodes in the graph formed by all returned paths:")
print(graph.nodes.keys())
Nodes in each returned path:
[6196955286285058052, 7998395137233256457, 8214567919347040275]
[6196955286285058052, 7998395137233256457, 8214567919347040275]
[6196955286285058052, 7998395137233256457, 5764609722057490441]
----------
Nodes in the graph formed by all returned paths:
dict_keys([6196955286285058052, 7998395137233256457, 8214567919347040275, 5764609722057490441])
GraphSet
GraphSet
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
id |
str | / | 图ID |
name |
str | / | 图名称 |
totalNodes |
int | / | 图中点的总数 |
totalEdges |
int | / | 图中边的总数 |
shards |
List[str] | [] |
用来存储图的Shard服务器的ID列表 |
partitionBy |
str | Crc32 |
用于图分片的哈希函数,包括Crc32 、Crc64WE 、Crc64XZ 和CityHash64 |
status |
str | / | 图状态,包括NORMAL 、LOADING_SNAPSHOT 、CREATING 、DROPPING 和SCALING |
description |
str | / | 图描述 |
slotNum |
int | 0 | 图分片使用的槽数量 |
response = Conn.gql("SHOW GRAPH")
graphs = response.alias("_graph").asGraphSets()
for graph in graphs:
print(graph.name)
DFS_EG
cyber
netflow
Schema
Schema
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
str | / | Schema名称 |
dbType |
DBType |
/ | Schema类型,包括DBNODE 和DBEDGE |
properties |
List[Property ] |
/ | 与Schema关联的属性列表 |
description |
str | / | Schema描述 |
total |
int | 0 | 属于该Schema的点或边总数 |
id |
int | / | Schema ID |
stats |
List[dict[str,any]] | [] |
一个字典列表,每个字典包括三个键:from (起点schema)、to (终点schema)以及count (点或边的数量) |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.gql("SHOW NODE SCHEMA", requestConfig)
schemas = response.alias("_nodeSchema").asSchemas()
for schema in schemas:
print(schema.name)
default
account
celebrity
country
movie
Property
Property
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
str | / | 属性名 |
type |
UltipaPropertyType |
/ | 属性值类型,包括INT32 、UINT32 、INT64 、UINT64 、FLOAT 、DOUBLE 、DECIMAL 、STRING 、TEXT 、DATETIME 、TIMESTAMP 、BLOB 、BOOL 、POINT 、LIST 、SET 、MAP 、UUID 、ID 、FROM 、FROM_UUID 、TO 、TO_UUID 、IGNORE 和UNSET |
subType |
List[UltipaPropertyType ] |
/ | 如果type 为LIST 或SET ,设定其元素类型;列表内只能包括一个UltipaPropertyType ,且只能为INT32 、UINT32 、INT64 、UINT64 、FLOAT 、DOUBLE 、DECIMAL 、STRING 、TEXT 、DATETIME 或TIMESTAMP |
schema |
str | / | 属性关联的Schema名称 |
description |
str | / | 属性描述 |
lte |
bool | / | 属性是否加载到引擎(LTE) |
read |
bool | / | 属性是否可读 |
write |
bool | / | 属性是否可写 |
encrypt |
str | / | 属性加密方法,包括AES128 、AES256 、RSA 和ECC |
extra |
str | / | 额外的属性信息 |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.gql("SHOW NODE account PROPERTY", requestConfig)
properties = response.alias("_nodeProperty").asProperties()
for property in properties:
print(property.name)
title
profile
age
name
logo
Attr
Attr
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
str | / | 返回的别名 |
values |
List[any] | / | 返回值 |
propertyType |
UltipaPropertyType |
/ | 返回属性的类型 |
resultType |
ResultType |
/ | 返回结果类型 |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.gql("MATCH (n:account) RETURN n.name LIMIT 3")
attr = response.alias("n.name").asAttr()
print("name:", attr.name)
print("values:", attr.values)
print("property type:", attr.propertyType.name)
print("result type:", attr.resultType.name)
name: n.name
values: ['Velox', 'K03', 'Lunatique']
property type: STRING
result type: RESULT_TYPE_ATTR
Table
Table
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
str | / | 表名称 |
headers |
List[Dict] | / | 表头 |
rows |
List[any] | / | 表中的行 |
Table
对象支持的方法:
方法 |
返回值 |
描述 |
---|---|---|
toKV() |
List[Dict] | 将表中的所有行转换成字典列表 |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.gql("MATCH (n:account) RETURN table(n._id, n.name) LIMIT 3")
table = response.get(0).asTable()
print("Header:")
print(table.headers)
print("First Row:")
print(table.toKV()[0])
Header:
[{'property_name': 'n._id', 'property_type': 'string'}, {'property_name': 'n.name', 'property_type': 'string'}]
First Row:
{'n._id': 'ULTIPA800000000000003B', 'n.name': 'Velox'}
HDCGraph
HDCGraph
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
str | / | HDC图名称 |
graphName |
str | / | HDC图的源图名称 |
status |
str | / | HDC图状态 |
stats |
str | / | HDC图的统计信息 |
isDefault |
str | / | 是否为源图的默认HDC图 |
hdcServerName |
str | / | 托管HDC图的HDC服务器名称 |
hdcServerStatus |
str | / | 托管HDC图的HDC服务器状态 |
config |
str | / | HDC图的配置 |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.uql("hdc.graph.show()", requestConfig)
hdcGraphs = response.alias("_hdcGraphList").asHDCGraphs()
for hdcGraph in hdcGraphs:
print(hdcGraph.name, "on", hdcGraph.hdcServerName)
miniCircle_hdc_graph on hdc-server-1
miniCircle_hdc_graph2 on hdc-server-2
Algo
Algo
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
str | / | 算法名称 |
type |
str | / | 算法类型 |
version |
str | / | 算法版本 |
params |
List[AlgoParam ] |
/ | 算法参数,每个AlgoParam 有属性name 和desc |
writeSupportType |
str | / | 算法支持的回写类型 |
canRollback |
str | / | 算法版本是否可回退 |
configContext |
str | / | 算法配置文件内容 |
response = Conn.uql("show().hdc('hdc-server-1')")
algos = response.alias("_algoList_from_hdc-server-1").asAlgos()
data = [[algo.name, algo.writeSupportType] for algo in algos if algo.type == "algo"]
headers = ["Name", "writeSupportType"]
print(tabulate.tabulate(data, headers=headers, tablefmt="grid"))
+-----------+--------------------+
| Name | writeSupportType |
+===========+====================+
| fastRP | DB,FILE |
+-----------+--------------------+
| struc2vec | DB,FILE |
+-----------+--------------------+
Projection
Projection
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
str | / | 映射名称 |
graphName |
str | / | 映射的源图名称 |
status |
str | / | 映射状态 |
stats |
str | / | 映射的统计信息 |
config |
str | / | 映射的配置 |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.uql("show().projection()", requestConfig)
projections = response.alias("_projectionList").asProjections()
for projection in projections:
print(projection.name)
miniCircle_projection_1
Index
Index
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
id |
str | / | 索引ID |
name |
str | / | 索引名称 |
properties |
str | / | 索引关联的属性 |
schema |
str | / | 索引关联的schema |
status |
str | / | 索引状态 |
size |
str | / | 索引大小(单位:字节) |
dbType |
DBType |
/ | 索引类型,包括DBNODE 和DBEDGE |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.gql("SHOW NODE INDEX", requestConfig)
indexList = response.alias("_nodeIndex").asIndexes()
for index in indexList:
print(index.schema, "-", index.properties, "-", index.schema)
account - gender(6),year - account
Privilege
Privilege
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
str | / | 权限名称 |
level |
PrivilegeLevel |
/ | 权限级别,包括SystemLevel 和Graphlevel |
response = Conn.uql("show().privilege()")
privileges = response.alias("_privilege").asPrivileges()
graphPrivileges = [privilege.name for privilege in privileges if privilege.level == PrivilegeLevel.Graphlevel]
print("Graph Privileges:", graphPrivileges)
systemPrivileges = [privilege.name for privilege in privileges if privilege.level == PrivilegeLevel.SystemLevel]
print("System Privileges:", systemPrivileges)
Graph Privileges: ['READ', 'INSERT', 'UPSERT', 'UPDATE', 'DELETE', 'CREATE_SCHEMA', 'DROP_SCHEMA', 'ALTER_SCHEMA', 'SHOW_SCHEMA', 'RELOAD_SCHEMA', 'CREATE_PROPERTY', 'DROP_PROPERTY', 'ALTER_PROPERTY', 'SHOW_PROPERTY', 'CREATE_FULLTEXT', 'DROP_FULLTEXT', 'SHOW_FULLTEXT', 'CREATE_INDEX', 'DROP_INDEX', 'SHOW_INDEX', 'LTE', 'UFE', 'CLEAR_JOB', 'STOP_JOB', 'SHOW_JOB', 'ALGO', 'CREATE_PROJECT', 'SHOW_PROJECT', 'DROP_PROJECT', 'CREATE_HDC_GRAPH', 'SHOW_HDC_GRAPH', 'DROP_HDC_GRAPH', 'COMPACT_HDC_GRAPH', 'SHOW_VECTOR_INDEX', 'CREATE_VECTOR_INDEX', 'DROP_VECTOR_INDEX', 'SHOW_CONSTRAINT', 'CREATE_CONSTRAINT', 'DROP_CONSTRAINT']
System Privileges: ['TRUNCATE', 'COMPACT', 'CREATE_GRAPH', 'SHOW_GRAPH', 'DROP_GRAPH', 'ALTER_GRAPH', 'TOP', 'KILL', 'STAT', 'SHOW_POLICY', 'CREATE_POLICY', 'DROP_POLICY', 'ALTER_POLICY', 'SHOW_USER', 'CREATE_USER', 'DROP_USER', 'ALTER_USER', 'SHOW_PRIVILEGE', 'SHOW_META', 'SHOW_SHARD', 'ADD_SHARD', 'DELETE_SHARD', 'REPLACE_SHARD', 'SHOW_HDC_SERVER', 'ADD_HDC_SERVER', 'DELETE_HDC_SERVER', 'LICENSE_UPDATE', 'LICENSE_DUMP', 'GRANT', 'REVOKE', 'SHOW_BACKUP', 'CREATE_BACKUP', 'SHOW_VECTOR_SERVER', 'ADD_VECTOR_SERVER', 'DELETE_VECTOR_SERVER']
Policy
Policy
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
str | / | 策略名称 |
systemPrivileges |
List[str] | / | 策略中包含的系统权限 |
graphPrivileges |
Dict[str,List[str]] | / | 策略中包含的图集权限;在字典中,键是图集名称,值是相应的图集权限 |
propertyPrivileges |
PropertyPrivilege |
/ | 策略中包含的属性权限;PropertyPrivilege 有node 和edge 两个属性,都是PropertyPrivilegeElement 对象 |
policies |
List[str] | / | 策略中包含的其他策略 |
PropertyPrivilegeElement
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
read |
List[List[str]] | / | 一个元素均为列表的列表;内部的每个列表包含三个字符串,分别指定图、schema和属性 |
write |
List[List[str]] | / | 一个元素均为列表的列表;内部的每个列表包含三个字符串,分别指定图、schema和属性 |
deny |
List[List[str]] | / | 一个元素均为列表的列表;内部的每个列表包含三个字符串,分别指定图、schema和属性 |
response = Conn.uql("show().policy('Tester')")
policy = response.alias("_policy").asPolicies()
print("Graph Privileges:", policy.graphPrivileges)
print("System Privileges:", policy.systemPrivileges)
print("Property Privileges:")
print("- Node (Read):", policy.propertyPrivileges.node.read)
print("- Node (Write):", policy.propertyPrivileges.node.write)
print("- Node (Deny):", policy.propertyPrivileges.node.deny)
print("- Edge (Read):", policy.propertyPrivileges.edge.read)
print("- Edge (Write):", policy.propertyPrivileges.edge.write)
print("- Edge (Deny):", policy.propertyPrivileges.edge.deny)
print("Policies:", policy.policies)
Graph Privileges: {'amz': ['ALGO', 'INSERT', 'DELETE', 'UPSERT'], 'StoryGraph': ['UPDATE', 'READ']}
System Privileges: ['TRUNCATE', 'KILL', 'TOP']
Property Privileges:
- Node (Read): [['*', '*', '*']]
- Node (Write): []
- Node (Deny): []
- Edge (Read): []
- Edge (Write): [['amz', '*', '*'], ['alimama', '*', '*']]
- Edge (Deny): [['miniCircle', 'review', 'value, timestamp']]
Policies: ['sales', 'manager']
User
User
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
username |
str | / | 用户名 |
password |
str | / | 密码 |
createdTime |
datetime | / | 用户创建时间 |
systemPrivileges |
List[str] | / | 授予用户的系统权限 |
graphPrivileges |
Dict[str,List[str]] | / | 授予用户的图集权限;在字典中,键是图集名称,值是相应的图集权限 |
propertyPrivileges |
PropertyPrivilege |
/ | 授予用户的属性权限;PropertyPrivilege 有node 和edge 两个属性,都是PropertyPrivilegeElement 对象 |
policies |
List[str] | / | 授予用户的策略 |
PropertyPrivilegeElement
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
read |
List[List[str]] | / | 一个元素均为列表的列表;内部的每个列表包含三个字符串,分别指定图、schema和属性 |
write |
List[List[str]] | / | 一个元素均为列表的列表;内部的每个列表包含三个字符串,分别指定图、schema和属性 |
deny |
List[List[str]] | / | 一个元素均为列表的列表;内部的每个列表包含三个字符串,分别指定图、schema和属性 |
response = Conn.uql("show().user('johndoe')")
user = response.alias("_user").asUsers()
print("Created Time:", user.createdTime)
print("Graph Privileges:", user.graphPrivileges)
print("System Privileges:", user.systemPrivileges)
print("Property Privileges:")
print("- Node (Read):", user.propertyPrivileges.node.read)
print("- Node (Write):", user.propertyPrivileges.node.write)
print("- Node (Deny):", user.propertyPrivileges.node.deny)
print("- Edge (Read):", user.propertyPrivileges.edge.read)
print("- Edge (Write):", user.propertyPrivileges.edge.write)
print("- Edge (Deny):", user.propertyPrivileges.edge.deny)
print("Policies:", user.policies)
Created Time: 2025-04-02 11:08:38
Graph Privileges: {'amz': ['ALGO', 'INSERT', 'DELETE', 'UPSERT'], 'StoryGraph': ['UPDATE', 'READ']}
System Privileges: ['TRUNCATE', 'KILL', 'TOP']
Property Privileges:
- Node (Read): [['*', '*', '*']]
- Node (Write): []
- Node (Deny): []
- Edge (Read): []
- Edge (Write): [['amz', '*', '*'], ['alimama', '*', '*']]
- Edge (Deny): [['miniCircle', 'review', 'value, timestamp']]
Policies: ['sales', 'manager']
Process
Process
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
processId |
str | / | 进程ID |
processQuery |
str | / | 进程执行的语句 |
status |
str | / | 进程状态 |
duration |
str | / | 任务的运行时长(单位:秒) |
response = Conn.uql("top()")
processes = response.alias("_top").asProcesses()
for process in processes:
print(process.processId)
1049435
Job
Job
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
id |
str | / | 作业ID |
graphName |
str | / | 作业执行所在的图名称 |
query |
str | / | 作业执行的语句 |
type |
str | / | 作业类型 |
errNsg |
str | / | 作业错误信息 |
result |
str | / | 作业结果 |
startTime |
str | / | 作业开始时间 |
endTime |
str | / | 作业结束时间 |
status |
str | / | 作业状态 |
progress |
str | / | 作业的进度更新,例如提示回写操作已开始 |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.gql("SHOW JOB", requestConfig)
jobs = response.alias("_job").asJobs()
for job in jobs:
if job.status == "FAILED":
print(job.id, "-", job.errMsg, "-", job.type)
51 - Fulltext name already exists. - CREATE_FULLTEXT
42 - Fulltext name already exists. - CREATE_FULLTEXT
26 - [engine] uuids should be unsigned integer - HDC_ALGO
26_1 - - HDC_ALGO
17 - [engine] all failed, because some nodes do not exist in db - HDC_ALGO
17_1 - - HDC_ALGO