The Ultipa Python driver provides a set of data structures designed to facilitate seamless interaction with the graph database. All data structures support getter methods to retrieve an attribute and setter methods to set the value of an attribute.
Node
A Node
object has the following attributes:
Attribute |
Type |
Default |
Description |
---|---|---|---|
uuid |
int | / | Node _uuid . |
id |
str | / | Node _id . |
schema |
str | / | Name of the schema the node belongs to. |
values |
Dict[str,any] | / | Node property key-value pairs. |
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
An Edge
object has the following attributes:
Attribute |
Type |
Default |
Description |
---|---|---|---|
uuid |
int | / | Edge _uuid . |
fromUuid |
int | / | Source node _uuid of the edge. |
toUuid |
int | / | Destination node _uuid of the edge. |
fromId |
str | / | Source node _id of the edge. |
toId |
str | / | Destination node _id of the edge. |
schema |
str | / | Name of the schema the edge belongs to. |
values |
Dict[str,any] | / | Edge property key-value pairs. |
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
A Path
object has the following attributes:
Attribute |
Type |
Default |
Description |
---|---|---|---|
nodeUUids |
List[int] | / | The list of node _uuid s in the path. |
edgeUuids |
List[int] | / | The list of edge _uuid s in the path |
nodes |
Dict[int, Node ] |
{} |
A dictionary of nodes in the path, where the key is the node’s _uuid , and the value is the corresponding node. |
edges |
Dict[int, Edge ] |
{} |
A dictionary of edges in the path, where the key is the edge’s _uuid , and the value is the corresponding edge. |
Methods on a Path
object:
Method |
Return |
Description |
---|---|---|
length() |
int | Gets the length of the path, i.e., the number of edges in the path. |
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
A Graph
object has the following attributes:
Attribute |
Type |
Default |
Description |
---|---|---|---|
paths |
List[Path ] |
[] |
The list of the returned paths. |
nodes |
Dict[int, Node ] |
{} |
A dictionary of nodes in the graph, where the key is the node’s _uuid , and the value is the corresponding node. |
edges |
Dict[int, Edge ] |
{} |
A dictionary of edges in the graph, where the key is the edge’s _uuid , and the value is the corresponding edge. |
Methods on a Graph
object:
Method |
Parameter |
Return |
Description |
---|---|---|---|
addNode() |
node: Node |
/ | Add a node to nodes . |
addEdge() |
edge: Edge |
/ | Add an edge to 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
A GraphSet
object has the following attributes:
Attribute |
Type |
Default |
Description |
---|---|---|---|
id |
str | / | Graph ID. |
name |
str | / | Required. Graph name. |
totalNodes |
int | / | Total number of nodes in the graph. |
totalEdges |
int | / | Total number of edges in the graph. |
shards |
List[str] | [] |
The list of IDs of shard servers where the graph is stored. |
partitionBy |
str | Crc32 |
The hash function used for graph sharding, which can be Crc32 , Crc64WE , Crc64XZ , or CityHash64 . |
status |
str | / | Graph status, which can be NORMAL , LOADING_SNAPSHOT , CREATING , DROPPING , or SCALING . |
description |
str | / | Graph description. |
slotNum |
int | 0 | The number of slots used for graph sharding. |
response = Conn.uql("show().graph()")
graphs = response.alias("_graph").asGraphSets()
for graph in graphs:
print(graph.name)
DFS_EG
cyber
netflow
Schema
A Schema
object has the following attributes:
Attribute |
Type |
Default |
Description |
---|---|---|---|
name |
str | / | Required. Schema name |
dbType |
DBType |
/ | Required. Schema type, which can be DBNODE or DBEDGE . |
properties |
List[Property ] |
/ | The list of properties associated with the schema. |
description |
str | / | Schema description |
total |
int | 0 | Total number of nodes or edges belonging to the schema. |
id |
int | / | Schema ID. |
stats |
list<Map{from, to, count}> | [] |
The count for each pair of start and end node schemas of an edge schema. |
response = Conn.uql("show().node_schema()")
schemas = response.alias("_nodeSchema").asSchemas()
for schema in schemas:
print(schema.name, "has", schema.total, "nodes")
default has 0 nodes
member has 7 nodes
organization has 19 nodes
Property
A Property
object has the following attributes:
Attribute |
Type |
Default |
Description |
---|---|---|---|
name |
str | / | Required. Property name. |
type |
UltipaPropertyType |
/ | Required. Property value type, which can be INT32 , UINT32 , INT64 , UINT64 , FLOAT , DOUBLE , DECIMAL , STRING , TEXT , DATETIME , TIMESTAMP , BLOB , BOOL , POINT , LIST , SET , MAP , NULL , UUID , ID , FROM , FROM_UUID , TO , TO_UUID , IGNORE , or UNSET . |
subType |
List[UltipaPropertyType ] |
/ | If the type is LIST or SET , sets its element type; only one UltipaPropertyType is allowed in the list, which can be INT32 , UINT32 , INT64 , UINT64 , FLOAT , DOUBLE , DECIMAL , STRING , TEXT , DATETIME , or TIMESTAMP . |
schema |
str | / | The associated schema of the property. |
description |
str | / | Property description. |
lte |
bool | / | Whether the property is LTE-ed. |
read |
bool | / | Whether the property is readable. |
write |
bool | / | Whether the property can be written. |
encrypt |
str | / | Encryption method of the property, which can be AES128 , AES256 , RSA , or ECC . |
extra |
str | / | Additional information about the property. |
requestConfig = RequestConfig(graph="miniCircle")
response = Conn.uql("show().node_property(@account)", requestConfig)
properties = response.alias("_nodeProperty").asProperties()
for property in properties:
print(property.name)
title
profile
age
name
logo
Table
A Table
object has the following attributes:
Attribute |
Type |
Default |
Description |
---|---|---|---|
name |
str | / | Table name. |
headers |
List[Dict] | / | Table headers. |
rows |
List[any] | / | Table rows. |
Methods on a Table
object:
Method |
Return |
Description |
---|---|---|
toKV() |
List[Dict] | Convert all rows in the table to a list of dictionaries. |
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'}
Algo
An Algo
object has the following attributes:
Attribute |
Type |
Description |
---|---|---|
name |
str | Algorithm name |
description |
str | Algorithm description |
version |
str | Algorithm version |
parameters |
dict | Algorithm parameters |
write_to_file_parameters |
dict | Algorithm file writeback parameters |
write_to_db_parameters |
dict | Algorithm property writeback parameters |
result_opt |
str | The code defines the execution methods supported by the algorithm. |
response = Conn.uql("show().algo()")
algos = response.alias("_algoList").asAlgos()
print(algos[0])
{'name': 'celf', 'description': 'celf', 'version': '1.0.0', 'result_opt': '25', 'parameters': {'seedSetSize': 'size_t,optional,1 as default', 'monteCarloSimulations': 'size_t,optional, 1000 as default', 'propagationProbability': 'float,optional, 0.1 as default'}, 'write_to_db_parameters': {}, 'write_to_file_parameters': {'filename': 'set file name'}}
Exta
An exta is a custom algorithm developed by users.
An Exta
object has the following attributes:
Attribute |
Type |
Description |
---|---|---|
name |
str | Exta name |
author |
str | Exta author |
version |
str | Exta version |
detail |
str | Content of the YML configuration file of the Exta |
response = Conn.uql("show().exta()")
extas = response.alias("_extaList").asExtas()
print(extas[0].name)
page_rank
Index
An Index
object has the following attributes:
Attribute |
Type |
Description |
---|---|---|
name |
str | Index name |
properties |
str | Property name of the index |
schema |
str | Schema name of the index |
status |
str | Index status (done or creating) |
size |
str | Index size in bytes |
DBType |
DBType | Index type (DBNODE or DBEDGE) |
response = Conn.uql("show().index()")
indexList = response.alias("_nodeIndex").asIndexes()
for index in indexList:
print(index.schema, index.properties, index.size)
account name 0
movie name 2526
response = Conn.uql("show().fulltext()")
indexList = response.alias("_edgeFulltext").asIndexes()
for index in indexList:
print(index.schema, index.properties, index.schema)
contentFull content review
Privilege
A Privilege
object has the following attributes:
Attribute |
Type |
Description |
---|---|---|
systemPrivileges |
List[str] | System privileges |
graphPrivileges |
List[str] | Graph privileges |
response = Conn.uql("show().privilege()")
privilege = response.alias("_privilege").asPrivilege()
print(privilege.systemPrivileges)
["TRUNCATE","COMPACT","CREATE_GRAPH","SHOW_GRAPH","DROP_GRAPH","ALTER_GRAPH","MOUNT_GRAPH","UNMOUNT_GRAPH","TOP","KILL","STAT","SHOW_POLICY","CREATE_POLICY","DROP_POLICY","ALTER_POLICY","SHOW_USER","CREATE_USER","DROP_USER","ALTER_USER","GRANT","REVOKE","SHOW_PRIVILEGE"]
Policy
A Policy
object has the following attributes:
Attribute |
Type |
Description |
---|---|---|
name |
str | Policy name |
systemPrivileges |
List[str] | System privileges included in the policy |
graphPrivileges |
dict | Graph privileges and the corresponding graphsets included in the policy |
propertyPrivileges |
dict | Property privileges included in the policy |
policies |
List[str] | Policies included in the policy |
response = Conn.uql("show().policy()")
policyList = response.alias("_policy").asPolicies()
for policy in policyList:
print(policy.name)
manager
operator
User
A User
object has the following attributes:
Attribute |
Type |
Description |
---|---|---|
username |
str | Username |
create |
str | When the user was created |
systemPrivileges |
List[str] | System privileges granted to the user |
graphPrivileges |
dict | Graph privileges and the corresponding graphsets granted to the user |
propertyPrivileges |
dict | Property privileges granted to the user |
policies |
List[str] | Policies granted to the user |
response = Conn.uql("show().user('Tester')")
user = response.alias("_user").asUsers()
print(user.toJSON())
{"create": 1721974206, "graphPrivileges": "{}", "policies": "[]", "propertyPrivileges": "{\"node\":{\"read\":[],\"write\":[[\"miniCircle\",\"account\",\"name\"]],\"deny\":[]},\"edge\":{\"read\":[],\"write\":[],\"deny\":[]}}", "systemPrivileges": "[]", "username": "Tester"}
Stats
A Stats
object has the following attributes:
Attribute |
Type |
Description |
---|---|---|
cpuUsage |
str | CPU usage in percentage |
memUsage |
str | Memory usage in megabytes |
expiredDate |
str | Expiration date of the license |
cpuCores |
str | Number of CPU cores |
company |
str | Company name |
serverType |
str | Server type |
version |
str | Version of the server |
response = Conn.uql("stats()")
stats = response.get(0).asStats()
print("CPU usage (%):", stats.cpuUsage)
print("Memory usage:", stats.memUsage)
CPU usage (%): 5.415697
Memory usage: 9292.265625
Process
A Process
object has the following attributes:
Attribute |
Type |
Description |
---|---|---|
processId |
String | Process ID |
processUql |
String | The UQL run with the process |
status |
String | Process status |
duration |
String | The duration in seconds the task has run so far |
requestConfig = RequestConfig(graphName="amz")
response = Conn.uql("top()", requestConfig)
processList = response.alias("_top").asProcesses()
for process in processList:
print(process.processId)
a_2_569_2
a_3_367_1
Task
A Task
object has the following attributes:
Attribute |
Type |
Description |
---|---|---|
Task_info |
Task_info | Task information including task_id , algo_name , start_time , writing_start_time , end_time , etc. |
param |
dict | Algorithm parameters and their corresponding values |
result |
dict | Algorithm result and statistics and their corresponding values |
requestConfig = RequestConfig(graphName="miniCircle")
response = Conn.uql("show().task()", requestConfig)
tasks = response.alias("_task").asTasks()
print(tasks[0].task_info)
print(tasks[0].param)
print(tasks[0].result)
{'task_id': 77954, 'server_id': 2, 'algo_name': 'louvain', 'start_time': 1728543848, 'writing_start_time': 1728543848, 'end_time': 1728543848, 'time_cost': 0, 'TASK_STATUS': 3, 'return_type': <ultipa.types.types_response.Return_Type object at 0x0000025E53C0F940>}
{"phase1_loop_num":"20","min_modularity_increase":"0.001"}
{'community_count': '10', 'modularity': '0.535017', 'result_files': 'communityID,ids,num'}
Attr
A Attr
object has the following attributes:
Attribute |
Type |
Description |
---|---|---|
name |
str | Attr name |
values |
any | Attr rows |
type |
ResultType |
Attr type |
response = Conn.uql("find().nodes({@ad}) as n return n.brand limit 5")
attr = response.alias("n.brand").asAttr()
print(attr.values)
[14655, 14655, 14655, 14655, 434760]