NebulaGraph in Jupyter Notebook

Introduce the brand new
ipython-ngql
python package that enhances your ability to connect to NebulaGraph from your Jupyter Notebook or iPython. Now we can do%ngql MATCH p=(n:player)->() RETURN p
to query from Jupyter Notebook and%ng_draw
to render the result.
1 Installation
Just do %pip install ipython-ngql
from Jupyter Notebook and load it up via %load_ext ngql
:
|
|
Then, connect the NebulaGraph with a line like this:
|
|
When connected, the cell will have an output of SHOW SPACES
.
💡 Note, you could install NebulaGraph dev env from Docker Desktop Extension Marketplace and literally have it ready with one click. Then, within the extension, go to “NebulaGraph AI” and click Install NX Mode to install NebulaGraph + Jupyter Notebook local dev env.
2 Query NebulaGraph
We could then do one-liner query with %ngql
or multi-line query with %%ngql
.
2.1 One-liner query
For instance:
|
|
2.2 Multi-line query
For instance
|
|
3 Draw the result
After any query result, we could render it visually with %ng_draw
:
|
|
And it’ll look like:
And the renderred result will be in a single-file html, which could be embeded in web pages like:
4 Other functionality
We could query %ngql help
to know more details of options for ipython-ngql. Here also introudce you some small features.
4.1 Get the pandas df query result
The result could be read from _
like:
4.2 Play with ResultSet result instead
By default, the return result is pandas df, but we could configure it as raw
to enable debugging for Python NebulaGraph Application code on query result handling, like:
|
|
4.3 Query Template
Besides, I brought the template support in Jinja2, thus we could do varibales like {{ variable }}
:
5 Future
I am planning to add more options on the %ng_draw
in the future, and it’s always welcome for your help to contribute more from https://github.com/wey-gu/ipython-ngql.