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.
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:
1
2
%ngql USE basketballplayer;
%ngql MATCH (v:player{name:"Tim Duncan"})-->(v2:player) RETURN v2.player.name AS Name;
After any query result, we could render it visually with %ng_draw:
1
2
3
4
5
6
7
# one query%ngqlGETSUBGRAPH2STEPSFROM"player101"YIELDVERTICESASnodes,EDGESASrelationships;%ng_draw# another query%ngqlmatchp=(:player)-[]->()returnpLIMIT5%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:
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.