UltipaConfig
UltipaConfig defines the information of server needed when connecting to an Ultipa graph database. The change of an UltipaConfig object will update the connection it established.
Item | Type | Default Value | Description |
---|---|---|---|
hosts | List[str] | Ultipa server hosts list | |
username | str | username of server | |
password | str | password of server | |
crtFilePath | str | crt file path | |
timeoutWithSeconds | int | 3600 | timeout seconds for any request |
consistency | bool | False | if use leader host to guarantee Consistency Read |
maxRecvSize | int | -1 | max byte when receiving data |
defaultGraph | str | default | name of graphset to use |
heartBeat | int | 10 | heartbeat seconds for all instances, set 0 to turn off heartbeat |
responseWithRequestInfo | bool | False | if return request info |
uqlLoggerConfig | LoggerConfig | logger configuration | |
Debug | bool | False | if use debug mode |
When setting
Debug
as True without settinguqlLoggerConfig
, the LoggerConfig class will automatically be imported and a uqlLoggerConfig will be created for debugging, but the log will not be written as file.
Example: Create a server connection and use graphset 'amz'
from ultipa import Connection, UltipaConfig
ultipaConfig = UltipaConfig()
ultipaConfig.hosts = ["192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061"]
ultipaConfig.username = "***"
ultipaConfig.password = "***"
ultipaConfig.defaultGraph = "amz"
conn = Connection.NewConnection(defaultConfig=ultipaConfig)
conn.test().Print()
LoggerConfig
LoggerConfig defines the information of log needed when connecting to an Ultipa graph database. The change of an LoggerConfig object will update the connection it established.
Item | Type | Default Value | Description |
---|---|---|---|
name | str | name of logger | |
filename | str | name of log file | |
isWriteToFile | bool | False | if write log as file |
isStream | bool | False | if output log to console |
level | logging | INFO | level of log |
Example: Create a server connection, use graphset 'amz' and output log to console
from ultipa import Connection, UltipaConfig
from ultipa.types.types import LoggerConfig
loggerConfig = LoggerConfig(name="myLog", isStream=True)
ultipaConfig = UltipaConfig()
ultipaConfig.hosts = ["192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061"]
ultipaConfig.username = "***"
ultipaConfig.password = "***"
ultipaConfig.defaultGraph = "amz"
ultipaConfig.uqlLoggerConfig = loggerConfig
conn = Connection.NewConnection(defaultConfig=ultipaConfig)
conn.test().Print()
RequestConfig
RequestConfig defines the information needed when sending non-insert type of requests to an Ultipa graph database.
Item | Type | Default Value | Description |
---|---|---|---|
graphName | str | name of graphset to use, or use defaultGraph of UltipaConfig if not set |
|
timeoutWithSeconds | int | 3600 | timeout seconds for the request |
useHost | str | send the request to a designated host, or sent to a random host if not set | |
useMaster | bool | False | if send the request to the leader to guarantee Consistency Read |
retry | Retry | retry config when request fails | |
stream | bool | False | if return stream |
threadNum | int | number of thread |
When setting useMaster as True as well as setting useHost to a follower, the request will be sent to the leader.
Example: Use graphset 'default' when establishing server connection, use graphset 'amz' when sending UQL to the the leader
from ultipa import Connection, UltipaConfig
from ultipa import RequestConfig
ultipaConfig = UltipaConfig()
ultipaConfig.hosts = ["192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061"]
ultipaConfig.username = "***"
ultipaConfig.password = "***"
conn = Connection.NewConnection(defaultConfig=ultipaConfig)
requestConfig = RequestConfig()
requestConfig.graphName = "amz"
requestConfig.useMaster = True
req = conn.uql("find().nodes() as nodes return nodes{*} limit 10", requestConfig)
req.Print()
InsertConfig
InsertConfig defines the information needed when sending insert type of requests to an Ultipa graph database.
Item | Type | Default Value | Description |
---|---|---|---|
graphName | str | name of graphset to use, or use defaultGraph of UltipaConfig if not set |
|
timeoutWithSeconds | int | 3600 | timeout seconds for the request |
useHost | str | send the request to a designated host, or sent to a random host if not set | |
useMaster | bool | False | if send the request to the leader to guarantee Consistency Read |
retry | Retry | retry config when request fails | |
stream | bool | False | if return stream |
threadNum | int | number of thread | |
insert_type | ULTIPA.InsertType | insert mode (NORMAL, UPSERT, OVERWRITE) | |
createNodeIfNotExist | bool | False | if create start/end nodes of edge when the end nodes do not exist in the graphset |
When setting useMaster as True as well as setting useHost to a follower, the request will be sent to the leader.
Example: Use graphset 'default' when establishing server connection, use graphset 'test' when executing InsertEdgesBatchAuto(), execute in upsert mode and allow start/end nodes of edge to be auto-created
from ultipa import Connection, UltipaConfig
from ultipa import InsertConfig, ULTIPA
ultipaConfig = UltipaConfig()
ultipaConfig.hosts = ["192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061"]
ultipaConfig.username = "***"
ultipaConfig.password = "***"
conn = Connection.NewConnection(defaultConfig=ultipaConfig)
insertConfig = InsertConfig(insertType=ULTIPA.InsertType.UPSERT)
insertConfig.graphName = "test"
insertConfig.createNodeIfNotExist = True
rows = [ULTIPA.Edge(values={"level": "A"},from_id="ULTIPA0000001",to_id="ULTIPA0000002",schema="default",uuid=1),
ULTIPA.Edge(values={"level": "B"},from_id="ULTIPA0000003",to_id="ULTIPA0000004",schema="default")]
req = conn.insertEdgesBatchAuto(rows, insertConfig)
req.Print()