Once you have installed the driver and set up an Ultipa instance, you can connect your application to the database.
You can establish a connection using the configurations from the UltipaConfig
class. See the UltipaConfig Parameters.
Creating the Connection
Creates a connection using the NewConnection
method of the Connection
class:
from ultipa import Connection, UltipaConfig
ultipaConfig = UltipaConfig()
# URI example: ultipaConfig.hosts = ["https://mqj4zouys.us-east-1.cloud.ultipa.com:60010"]
ultipaConfig.hosts = ["192.168.1.85:60061", "192.168.1.87:60061", "192.168.1.88:60061"]
ultipaConfig.username = "<username>"
ultipaConfig.password = "<password>"
Conn = Connection.NewConnection(defaultConfig=ultipaConfig)
# Tests the connection: The connection is successfully established if the code is 0
response = Conn.test()
print("Code =", response.status.code)
Code = 0
Using Configuration File
This example demonstrates how to use the configuration file .env
to establish a connection:
import os
from pathlib import Path
from dotenv import dotenv_values, load_dotenv
from ultipa import Connection, UltipaConfig
# Loads the .env file and overrides system environment variables
env_path = Path('./.env')
env_dict = dotenv_values(dotenv_path=env_path)
load_dotenv(encoding='utf-8', override=True)
hosts = os.getenv("hosts").split(",")
username = os.getenv("username")
password = os.getenv("password")
ultipaConfig = UltipaConfig(hosts=hosts, username=username, password=password, heartBeat=10)
Conn = Connection.NewConnection(defaultConfig=ultipaConfig)
response = Conn.test()
# The connection is successfully established if the code is 0
print("Code =", response.status.code)
Code = 0
Example of the .env
file:
#hosts=https://mqj4zouys.us-east-1.cloud.ultipa.com:60010
hosts=192.168.1.85:60061,192.168.1.86:60061,192.168.1.87:60061
username=<username>
password=<password>
passwordEncrypt=PasswordEncrypt.MD5
defaultGraph=miniCircle
#crt=F:\\ultipa.crt
#maxRecvSize=10240
UltipaConfig Parameters
The UltipaConfig
class has the following parameters:
Parameter |
Type |
Default |
Description |
---|---|---|---|
hosts |
List[str] | / | Required. A comma-separated list of database server IPs or URLs. If a URL does not start with https:// or http:// , http:// is prefixed by default. |
username |
str | / | Required. Username of the host authentication. |
password |
str | / | Required. Password of the host authentication. |
defaultGraph |
str | / | Name of the graph to use by default in the database. |
crt |
str | / | The file path of the SSL certificate used for secure connections. |
passwordEncrypt |
PasswordEncrypt |
PasswordEncrypt.MD5 |
Password encryption method of the driver. Supports MD5 , LDAP and NOTHING . |
timeout |
int | 15 | Connection timeout threshold (in second). |
heartBeat |
int | 0 | The heartbeat interval (in millisecond), used to keep the connection alive. Set to 0 to disable. |
maxRecvSize |
int | 32 | The maximum size (in MB) of the received data. |
debug |
bool | False | Whether to use the debug mode. |