UltipaDocs
Try Playground
  • Introduction
    • Installation
    • Connection
      • Overview and Request Configuration
      • UQL Execution
      • GQL Execution
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Result Processing
    • Driver Data Classes
    • Installation
    • Connection
      • Overview and Request Configuration
      • UQL Execution
      • GQL Execution
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Result Processing
    • Driver Data Classes
    • Quick Start
    • Connect to Database
    • Query the Database
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Process Query Results
    • Data Structures
    • Quick Start
    • Connect to Database
    • Query the Database
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Process Query Results
    • Data Structures
    • Installation
    • Connection
    • Request Configuration
    • UQL Execution
    • GQL Execution
    • Graphset Management
    • Schema and Property Management
    • Data Insertion and Deletion
    • Query Acceleration
    • Algorithm Management
    • Downloads and Exports
    • Process and Task Management
    • Access Management
    • Server Statistics
    • Result Processing
    • Types Mapping Ultipa and C#
  • RESTful API
  1. Docs
  2. /
  3. Ultipa Drivers
  4. /
  5. Python

Connection

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 UltipaConfig. See UltipaConfig Attributes.

Creating a Connection

Creates a connection using Connection.NewConnection():

Python
from ultipa import Connection, UltipaConfig

ultipaConfig = UltipaConfig()
# URI example: ultipaConfig.hosts = ["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
isSuccess = Conn.test()
print("Connection succeeds:", isSuccess)
Output
Connection succeeds: True

Using Configuration File

This example demonstrates how to use the configuration file .env to establish a connection:

Python
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)

# Tests the connection
response = Conn.test()
print(response.status.code.name)
Output
SUCCESS

Example of the .env file:

.env
#hosts=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=MD5
defaultGraph=miniCircle
#crt=F:\\ultipa.crt
#maxRecvSize=10240

UltipaConfig Attributes

The UltipaConfig class includes the following attributes:

Attribute
Type
Default
Description
hostsList[str]/Required. A comma-separated list of database server IPs or URLs. The protocol is automatically identified, do not include https:// or http:// as a prefix in the URL.
usernamestr/Required. Username of the host authentication.
passwordstr/Required. Password of the host authentication.
defaultGraphstr/Name of the graph to use by default in the database.
crtstr/The file path of the SSL certificate used for secure connections.
passwordEncryptstrMD5Password encryption method of the driver. Supports MD5, LDAP and NOTHING.
timeoutintMaximumRequest timeout threshold (in seconds).
heartbeatint0The heartbeat interval (in milliseconds), used to keep the connection alive. Set to 0 to disable.
maxRecvSizeint32The maximum size (in MB) of the received data.