Oracle Developers
Published in

Oracle Developers

Oracle Graph in Python (Setup Jupyter)

Oracle Graph can be accessed through Python via Jupyter notebooks, enabling data analysts and developers to easily add powerful graph analytics to their applications. Jupyter notebooks are a great way to get started quickly with exploring data, visualizing it, and performing graph analysis. And they’re easy to use, even if you don’t know a lot about graphs.

In this post, we’ll show the first step: how to install Jupyter in the cloud environment where you set up Oracle Graph. In the previous articles, “Building Oracle Graph in the Cloud” for both ADB and DBCS, we built a Graph Server from a Marketplace image, so we will install Jupyter on the same compute instance.

Install Jupyter

Open port 8888 to access Jupyter via web browsers.

We can temporally set to allow access from all IP addresses. In production use, restrict the IP addresses of clients for better security.

Log in to the compute instance.

$ ssh <public_ip_address> -l opc -i <secret_key_file>

Install Jupyter. We will be following the official instructions below.

$ sudo pip3 install --upgrade pip
$ pip3 install jupyter

Verify that the jupyter command is available.

$ jupyter --version
Selected Jupyter core packages...
IPython : 8.3.0
ipykernel : 6.13.0
ipywidgets : 7.7.0
jupyter_client : 7.3.0
jupyter_core : 4.10.0
jupyter_server : 1.17.0
jupyterlab : not installed
nbclient : 0.6.0
nbconvert : 6.5.0
nbformat : 5.3.0
notebook : 6.4.11
qtconsole : 5.3.0
traitlets : 5.1.1

If the command is not found, make sure the PATH environment variable is properly set.

$ vi ~/.bash_profile# User specific environment and startup programs
export PATH
$ source ~/.bash_profile

Generate a configuration file.

$ jupyter notebook --generate-config
Writing default config to: /home/opc/.jupyter/

Change the settings to allow access from all IP addresses.

$ vi /home/opc/.jupyter/ The IP address the notebook server will listen on.
#c.NotebookApp.ip = 'localhost'
c.NotebookApp.ip = '*'

Set the login password.

$ jupyter notebook password
Enter password:
Verify password:
[NotebookPasswordApp] Wrote hashed password to /home/opc/.jupyter/jupyter_notebook_config.json

Create a root directory for Jupyter, navigate there, and start Jupyter.

$ mkdir ~/jupyter
$ cd ~/jupyter
$ jupyter notebook --no-browser
[W 03:30:05.192 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 03:30:05.196 NotebookApp] Serving notebooks from local directory: /home/opc/jupyter
[I 03:30:05.196 NotebookApp] Jupyter Notebook 6.4.11 is running at:
[I 03:30:05.197 NotebookApp] http://oraclegraph-instance:8888/
[I 03:30:05.197 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

Configure the firewall to open port 8888.

$ sudo firewall-cmd --permanent --zone=public --add-port=8888/tcp
$ sudo firewall-cmd --reload
$ sudo firewall-cmd --list-all

Access http://<public_ip_address>:8888/ with a web browser.

Input the password and log in.

Jupyter is now installed.

Connect to Graph Server

Let’s connect to the Graph Server and run a PGQL query.

The first cell creates a session to the Graph Server. The password entered here is the one set for the database user, GRAPHUSER. Graph Server will query the database and, if this user is successfully authenticated, create a session and return a session ID.

import as graph_serverbase_url = "https://localhost:7007"
username = "graphuser"
password = "<password>"
instance = graph_server.get_instance(base_url, username, password)
session = instance.create_session("jupyter")
analyst = session.create_analyst()
print(session)--PgxSession(id: 9021c495-f3c4-4040-9aae-4c38814fc59b, name: jupyter)

Get the graph hr, which is loaded by default, so the response will show the number of nodes and edges of the graph.

graph = session.get_graph("hr")
--PgxGraph(name: hr, v: 215, e: 509, directed: True, memory(Mb): 0)

This is a PGQL query to get five edges and the vertices at both ends.

FROM MATCH (v1)-[e]->(v2) ON hr

Using this environment, we will see how to visualize query results, perform graph algorithms, and more, in future articles. Stay tuned!

Please learn more about Oracle Graph from:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store