Visually query Spanner Graph data in notebooks.
Project description
Spanner Graph Notebook: Explore Your Data Visually
The Spanner Graph Notebook tool provides an efficient way for you to query Spanner Graph visually in a notebook environment (e.g. Jupyter Notebook and Google Colab). Using GQL query syntax, you can can extract graph insights and relationship patterns, including node and edge properties, neighbor analysis, schema metadata, and diverse layout topologies.
Install dependencies
All dependencies below must be installed before using the tool.
Install the gcloud
CLI
gcloud
CLI is needed for authentication. Follow the installation manual to install.
Install dependencies
Download this package and install its dependencies. Python dependencies should ideally be installed in a managed Python environment using tools like conda
or virtualenv
.
When in the root directory of the package, follow the command below to create a managed Python environment (example based on virtualenv
) and install dependencies.
# Create the virtualenv `viz`.
python3 -m venv viz
# Activate the virtualenv.
source viz/bin/activate
# Install dependencies.
pip install .
Using
Launch notebook and follow steps in sample.ipynb
When in the root directory of the package, run jupyter notebook
to launch Jupyter Notebook.
jupyter notebook
As Jupyter local server runs, it will open up a web portal. You can open open the sample.ipynb
to step through an example.
You must run %load_ext spanner_graphs
to load this package. sample.ipynb
contains this cell already.
%%spanner_graph
magic command
This package provides a %%spanner_graph
magic command, which visualizes graph data in the notebook output cell.
Query and visualize a local dataset with --mock
flag
Using the --mock
flag for %%spanner_graph
, you can visualize local graph datasets without connecting to a live Cloud Spanner database. The mock
dataset renders a network of person
and account
nodes, along with edges in between. There is an inserted cell in sample.ipynb
for the code below.
%%spanner_graph --mock
Visualize graph queries from your Spanner Graph database
Authentication
To connect to your Spanner database, you need to first authenticate via gcloud auth
. gcloud
CLI is needed to use the tool. Follow the installation manual to install.
sample.ipynb
has inserted a code cell for authentication below. Running this opens a new browser tab for the Google Cloud authentication process.
!gcloud auth application-default login
Query and visualize Spanner Graph data
Using the %%spanner_graph
magic command, you can visualize graph query results from your Spanner database.
The magic command needs to be used with your GCP resource info and a query string:
- a GCP project id for
--project
option - a Spanner instance id for
--instance
option - a Spanner Graph database id for
--database
option - a GQL query string
Query Requirements
Use TO_JSON
function to return graph elements
Graph queries must use TO_JSON
function in the RETURN
statement to visualize paths, nodes and edges. We recommend visualizing paths for data completeness and ease of use.
👍 Good example returning a path as JSON.
GRAPH FinGraph
MATCH query_path = (person:Person {id: 5})-[owns:Owns]->(accnt:Account)
RETURN TO_JSON(query_path) AS path_json
👍 Good example returning a path as JSON in a multiple-hop query.
GRAPH FinGraph
MATCH query_path = (src:Account {id: 9})-[edge]->{1,3}(dst:Account)
RETURN TO_JSON(query_path) as path_json
👍 Good example returning multiple paths as JSON.
GRAPH FinGraph
MATCH path_1 = (person:Person {id: 5})-[:Owns]->(accnt:Account),
path_2 = (src:Account {id: 9})-[:Transfers]->(dst:Account)
RETURN TO_JSON(path_1) as path_1,
TO_JSON(path_2) as path_2
👎 Anti-example returning nodes properties rather than JSON format graph elements.
Scalar results other than JSON format graph elements cannot be visualized.
GRAPH FinGraph
MATCH (person:Person {id: 5})-[owns:Owns]->(accnt:Account)
RETURN person.id AS person,
owns.amount AS owns,
accnt.id AS accnt;
👎 Anti-example returning each node and edges in JSON format verbosely. This will
work but not as easy as returning a path directly.
GRAPH FinGraph
MATCH (person:Person {id: 5})-[owns:Owns]->(accnt:Account)
RETURN TO_JSON(person) AS person_json,
TO_JSON(owns) AS owns_json,
TO_JSON(accnt) AS accnt_json,
Testing changes
After adding new changes, please run unit and integration tests with the command below:
cd spanner_graphs && python -m unittest discover -s tests -p "*_test.py"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file spanner_graph_notebook-1.0.7.tar.gz
.
File metadata
- Download URL: spanner_graph_notebook-1.0.7.tar.gz
- Upload date:
- Size: 2.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aab5560c38633cadbe167ac9e06c4efb955fee513b6ea6c26f7ed1e90d939881 |
|
MD5 | e4ff4f4079d8917e902591ed0725fbbe |
|
BLAKE2b-256 | 9b9b2102dbe52fc2be97aaa788f9d8beba8521b814b3dc7dbb96584d9470ab1f |
Provenance
The following attestation bundles were made for spanner_graph_notebook-1.0.7.tar.gz
:
Publisher:
publish-to-pypi.yml
on cloudspannerecosystem/spanner-graph-notebook
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
spanner_graph_notebook-1.0.7.tar.gz
- Subject digest:
aab5560c38633cadbe167ac9e06c4efb955fee513b6ea6c26f7ed1e90d939881
- Sigstore transparency entry: 161522949
- Sigstore integration time:
- Permalink:
cloudspannerecosystem/spanner-graph-notebook@85174e9281145dda6aae796635c47642bda51eef
- Branch / Tag:
refs/tags/v1.0.7
- Owner: https://github.com/cloudspannerecosystem
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
publish-to-pypi.yml@85174e9281145dda6aae796635c47642bda51eef
- Trigger Event:
release
- Statement type:
File details
Details for the file spanner_graph_notebook-1.0.7-py3-none-any.whl
.
File metadata
- Download URL: spanner_graph_notebook-1.0.7-py3-none-any.whl
- Upload date:
- Size: 2.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 337f074b80e97f667dc2ff789937f02381b9e25f511bccf36178e94517ae8d07 |
|
MD5 | 2b887bf61a97c942f3690fe023a0744a |
|
BLAKE2b-256 | 82ceedf8dc6b04c3e0c88242a462578ee685d9d3177b517acfae7a9d92f62cd0 |
Provenance
The following attestation bundles were made for spanner_graph_notebook-1.0.7-py3-none-any.whl
:
Publisher:
publish-to-pypi.yml
on cloudspannerecosystem/spanner-graph-notebook
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
spanner_graph_notebook-1.0.7-py3-none-any.whl
- Subject digest:
337f074b80e97f667dc2ff789937f02381b9e25f511bccf36178e94517ae8d07
- Sigstore transparency entry: 161522950
- Sigstore integration time:
- Permalink:
cloudspannerecosystem/spanner-graph-notebook@85174e9281145dda6aae796635c47642bda51eef
- Branch / Tag:
refs/tags/v1.0.7
- Owner: https://github.com/cloudspannerecosystem
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
publish-to-pypi.yml@85174e9281145dda6aae796635c47642bda51eef
- Trigger Event:
release
- Statement type: