|
3 | 3 | [](https://pypi.org/project/neo4j-viz/) |
4 | 4 | [](https://pypi.org/project/neo4j-viz/) |
5 | 5 |  |
| 6 | +[](https://neo4j.com/docs/nvl-python/preview/) |
| 7 | +[](https://discord.gg/neo4j) |
| 8 | +[](https://community.neo4j.com) |
| 9 | +[](https://pypi.org/project/neo4j-viz/) |
| 10 | + |
| 11 | +`neo4j-viz` is a Python package for creating interactive graph visualizations based on data from Neo4j products. |
| 12 | + |
| 13 | +The output is of type `IPython.display.HTML` and can be viewed directly in a Jupyter Notebook, Streamlit. |
| 14 | +Alternatively, you can export the output to a file and view it in a web browser. |
6 | 15 |
|
7 | | -`neo4j-viz` is a Python package for creating interactive graph visualizations. |
8 | 16 | The package wraps the [Neo4j Visualization JavaScript library (NVL)](https://neo4j.com/docs/nvl/current/). |
9 | 17 |
|
10 | 18 | Proper documentation is forthcoming. |
11 | 19 |
|
12 | | -**WARNING:** |
13 | | -This package is still in development and the API is subject to change. |
| 20 | +> [!WARNING] |
| 21 | +> This package is still in development and the API is subject to change. |
14 | 22 |
|
15 | 23 |
|
16 | 24 | ## Some notable features |
@@ -39,8 +47,69 @@ This package is still in development and the API is subject to change. |
39 | 47 | Please note that this list is by no means exhaustive. |
40 | 48 |
|
41 | 49 |
|
42 | | -## Installation |
| 50 | +## Getting started |
43 | 51 |
|
44 | | -``` |
| 52 | + |
| 53 | +### Installation |
| 54 | + |
| 55 | +Simply install with pip: |
| 56 | + |
| 57 | +```sh |
45 | 58 | pip install neo4j-viz |
46 | | -``` |
| 59 | +``` |
| 60 | + |
| 61 | + |
| 62 | +### Basic usage |
| 63 | + |
| 64 | +We will use a small toy graph representing the purchase history of a few people and products. |
| 65 | + |
| 66 | +We start by instantiating the [Nodes](https://neo4j.com/docs/nvl-python/preview/api-reference/node.html) and |
| 67 | +[Relationships](https://neo4j.com/docs/nvl-python/preview/api-reference/relationship.html) we want in our graph. |
| 68 | +The only mandatory fields for a node are the "id", and "source" and "target" for a relationship. |
| 69 | +But the other fields can optionally be used to customize the appearance of the nodes and relationships in the |
| 70 | +visualization. |
| 71 | + |
| 72 | +Lastly we create a |
| 73 | +[VisualizationGraph](https://neo4j.com/docs/nvl-python/preview/api-reference/visualization-graph.html) object with the |
| 74 | +nodes and relationships we created, and call its `render` method to display the graph. |
| 75 | + |
| 76 | +```python |
| 77 | +from neo4j_viz import Node, Relationship, VisualizationGraph |
| 78 | + |
| 79 | +nodes = [ |
| 80 | + Node(id=0, size=10, caption="Person"), |
| 81 | + Node(id=1, size=10, caption="Product"), |
| 82 | + Node(id=2, size=20, caption="Product"), |
| 83 | + Node(id=3, size=10, caption="Person"), |
| 84 | + Node(id=4, size=10, caption="Product"), |
| 85 | +] |
| 86 | +relationships = [ |
| 87 | + Relationship( |
| 88 | + source=0, |
| 89 | + target=1, |
| 90 | + caption="BUYS", |
| 91 | + ), |
| 92 | + Relationship( |
| 93 | + source=0, |
| 94 | + target=2, |
| 95 | + caption="BUYS", |
| 96 | + ), |
| 97 | + Relationship( |
| 98 | + source=3, |
| 99 | + target=2, |
| 100 | + caption="BUYS", |
| 101 | + ), |
| 102 | +] |
| 103 | + |
| 104 | +VG = VisualizationGraph(nodes=nodes, relationships=relationships) |
| 105 | + |
| 106 | +VG.render() |
| 107 | +``` |
| 108 | + |
| 109 | +This will return a `IPython.display.HTML` object that can be rendered in a Jupyter Notebook or streamlit application. |
| 110 | + |
| 111 | + |
| 112 | +### Examples |
| 113 | + |
| 114 | +For more extensive examples, including how to import graphs from Neo4j GDS projections and Pandas DataFrames, |
| 115 | +checkout the [tutorials chapter](https://neo4j.com/docs/nvl-python/preview/tutorials/index.html) in the documentation. |
0 commit comments