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. Database Operations

Data Export

This section introduces methods for exporting nodes and edges from graphs.

export()

Exports nodes or edges from the graph.

Parameters

  • exportRequest: ExportRequest: Configurations for the export request, including attributes dbType, schema, selectProperties and graph.
  • cb: Callable[[List[Node], List[Edge]], None]: The callback function that gets executed when data is exported.
  • config: RequestConfig (Optional): Request configuration.

Returns

  • None.
Python
## Exports 'account' nodes in the graph 'miniCircle'

batch_counter = 0 # Global counter for batch tracking

exportRequest = ExportRequest(
    dbType=DBType.DBNODE,
    schema="account",
    selectProperties=["_id", "name", "year"],
    graph="miniCircle"
)

def handle_export(nodes: List[Node], edges: List[Edge]): # Defines the callback function
    global batch_counter
    batch_counter += 1

    try:
        schema = exportRequest.schema
        if nodes:
            df_nodes = pd.DataFrame([node.__dict__ for node in nodes]) # Converts to dictionary
            df_nodes.to_csv(f"{schema}_nodes.csv", mode="a", index=False)
            print(f"Batch {batch_counter} exported")
        if edges:
            df_edges = pd.DataFrame([edge.__dict__ for edge in edges]) # Converts to dictionary
            df_edges.to_csv(f"{schema}_edges.csv", mode="a", index=False)
            print(f"Batch {batch_counter} exported")
    except Exception as e:
        print(f"Batch {batch_counter} export failed: {e}")

Conn.export(exportRequest, handle_export)
Output
Batch 1 exported
Batch 2 exported
Batch 3 exported

The file account_nodes.csv is exported to the same directory as the file you executed.

Full Example

example.py
from typing import List
import pandas as pd
from ultipa import UltipaConfig, Connection, ExportRequest, DBType, Node, Edge

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)

# Exports 'account' nodes in the graph 'miniCircle'

batch_counter = 0 # Global counter for batch tracking

exportRequest = ExportRequest(
    dbType=DBType.DBNODE,
    schema="account",
    selectProperties=["_id", "name", "year"],
    graph="miniCircle"
)

def handle_export(nodes: List[Node], edges: List[Edge]): # Defines the callback function
    global batch_counter
    batch_counter += 1

    try:
        schema = exportRequest.schema
        if nodes:
            df_nodes = pd.DataFrame([node.__dict__ for node in nodes]) # Converts to dictionary
            df_nodes.to_csv(f"{schema}_nodes.csv", mode="a", index=False)
            print(f"Batch {batch_counter} exported")
        if edges:
            df_edges = pd.DataFrame([edge.__dict__ for edge in edges]) # Converts to dictionary
            df_edges.to_csv(f"{schema}_edges.csv", mode="a", index=False)
            print(f"Batch {batch_counter} exported")
    except Exception as e:
        print(f"Batch {batch_counter} export failed: {e}")

Conn.export(exportRequest, handle_export)