Use Oracle Graph Python Client with Autonomous Database

Rahul Tasker
Oracle Developers
Published in
5 min readFeb 16, 2023

--

In this article we will walk through the steps to use the Oracle Graph Client with Autonomous Database. The Autonomous Database Graph Client makes it easy to connect to, query, and work with graphs in Graph Studio from a Python or Java client. This enables developers to work with Graph Studio programmatically instead of using the UI. In this example, we will use the python client on a Jupyter notebook to query an existing graph in Graph Studio.

Prerequisites

  1. You have an Oracle Cloud Account.
  2. You have created an Autonomous Database instance, and a graph enabled user. If you have not, you can find the instructions to do so here.
  3. You have created the BANK_GRAPH. You can find the instructions to do so in this Oracle Livelab (Labs 1&2).
  4. You have Python 3.9.0 or higher, and Jupyter installed on the same machine.

Download and Install the Oracle Graph Client

  1. Download the latest version of Oracle Graph Client from here. Select the link that says “Oracle Graph Client” for the latest version.

2. Select the platform that best applies to your machine.

3. Since we are using the ADB Graph Client, we only need to download the Graph Client. Everything else can be unchecked. Be sure to review and check the license agreement at the top left of the screen and select Download.

4. A dmg file should appear in your Downloads folder for the Oracle Download Manager. Launch this application.

5. When the Oracle Download Manager is open, select your desired download location, and select Next.

6. Once the download is complete, you can close the application.

7. Open your terminal, navigate to the folder you entered in the Oracle Download Manager (Downloads folder by default). Unzip the folder that was downloaded. This will keep the graph client zip file zipped. Other methods may unzip that folder.

8. Install the graph client using pip. You should see a success message at after installing.

pip install oracle-graph-client-23.1.0.zip

You have installed Oracle Graph Client on your machine. Next, we will use the Python client in a Jupyter notebook to query from the BANK_GRAPH in Graph Studio.

Set up Notebook Environment

  1. Download the sample notebook from this GitHub repository, under the adb-client-jupyter folder, to your local machine.

2. Launch Jupyter notebook and open the sample notebook.

3. Click the Run button through the paragraphs for the first step. Notice that the second step requires some values from our OCI tenancy.

4. Log into your OCI tenancy and navigate to your tenancy details.

5. Copy the tenancy ocid. Navigate back to the jupyter notebook and replace <tenancy_ocid> with the copied value.

6. Navigate to your Autonomous Database instance. Copy the Database name and database ocid.

7. Navigate back to the jupyter notebook and replace <autonomous_database_name> with the database name value and replace the <autonomous_database_ocid> with the ocid.

8. From your ADB instance, select the Tool Configuration tab. Copy the Graph Studio URL. Navigate back to the jupyter notebook and replace endpoint value with the copied URL, removing the graphstudio/ extension from the URL.

9. Replace <graphuser_password> with the password for your GRAPHUSER and run the remaining paragraphs for the second step. These will check if the environment is started and start the graph environment.

Use Autonomous Database Graph Client

  1. Run through step 3 to create the PGX Session and load the graph into memory.

2. Run through step 4 to run the PageRank algorithm. This will add a pagerank property to the nodes in the graph. These represent the importance of each node within the graph, based on the number incoming relationships and the importance of the corresponding source nodes.

3. Run through step 5 to query the graph for the account ID and the corresponding PageRank value.

4. Run through step 6 to convert the result set to a pandas dataframe and use to gather some statistics from the dataframe.

5. Run through step 7 to create meaningful visualization charts.

6. Optionally, run through step 8 to close the PGX session.

Please learn more about Oracle Graph from:

If you’re curious about the goings-on of Oracle Developers in their natural habitat, come join us on our public Slack channel!

--

--

Rahul Tasker
Oracle Developers

Product Manager of Oracle Spatial and Oracle Graph. The views expressed here are my own, and the sample scripts in the articles are not supported.