Skip to content

Commit 819b6dc

Browse files
authored
Merge pull request #84 from neo4j/getting-started-readme
Extend Getting started in READMEs with small example
2 parents e665de0 + 6e3eaca commit 819b6dc

File tree

2 files changed

+132
-7
lines changed

2 files changed

+132
-7
lines changed

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,66 @@ Please note that this list is by no means exhaustive.
5151

5252
## Getting started
5353

54-
```
54+
55+
### Installation
56+
57+
Simply install with pip:
58+
59+
```sh
5560
pip install neo4j-viz
5661
```
5762

63+
64+
### Basic usage
65+
66+
We will use a small toy graph representing the purchase history of a few people and products.
67+
68+
We start by instantiating the [Nodes](https://neo4j.com/docs/nvl-python/preview/api-reference/node.html) and
69+
[Relationships](https://neo4j.com/docs/nvl-python/preview/api-reference/relationship.html) we want in our graph.
70+
The only mandatory fields for a node are the "id", and "source" and "target" for a relationship.
71+
But the other fields can optionally be used to customize the appearance of the nodes and relationships in the
72+
visualization.
73+
74+
Lastly we create a
75+
[VisualizationGraph](https://neo4j.com/docs/nvl-python/preview/api-reference/visualization-graph.html) object with the
76+
nodes and relationships we created, and call its `render` method to display the graph.
77+
78+
```python
79+
from neo4j_viz import Node, Relationship, VisualizationGraph
80+
81+
nodes = [
82+
Node(id=0, size=10, caption="Person"),
83+
Node(id=1, size=10, caption="Product"),
84+
Node(id=2, size=20, caption="Product"),
85+
Node(id=3, size=10, caption="Person"),
86+
Node(id=4, size=10, caption="Product"),
87+
]
88+
relationships = [
89+
Relationship(
90+
source=0,
91+
target=1,
92+
caption="BUYS",
93+
),
94+
Relationship(
95+
source=0,
96+
target=2,
97+
caption="BUYS",
98+
),
99+
Relationship(
100+
source=3,
101+
target=2,
102+
caption="BUYS",
103+
),
104+
]
105+
106+
VG = VisualizationGraph(nodes=nodes, relationships=relationships)
107+
108+
VG.render()
109+
```
110+
111+
This will return a `IPython.display.HTML` object that can be rendered in a Jupyter Notebook or streamlit application.
112+
113+
58114
### Examples
59115

60116
For some Jupyter Notebook and streamlit examples, checkout the [/examples](/examples) directory.

python-wrapper/README.md

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
33
[![Latest version](https://img.shields.io/pypi/v/neo4j-viz)](https://pypi.org/project/neo4j-viz/)
44
[![PyPI downloads month](https://img.shields.io/pypi/dm/neo4j-viz)](https://pypi.org/project/neo4j-viz/)
55
![Python versions](https://img.shields.io/pypi/pyversions/neo4j-viz)
6+
[![Documentation](https://img.shields.io/badge/Documentation-latest-blue)](https://neo4j.com/docs/nvl-python/preview/)
7+
[![Discord](https://img.shields.io/discord/787399249741479977?label=Chat&logo=discord)](https://discord.gg/neo4j)
8+
[![Community forum](https://img.shields.io/website?down_color=lightgrey&down_message=offline&label=Forums&logo=discourse&up_color=green&up_message=online&url=https%3A%2F%2Fcommunity.neo4j.com%2F)](https://community.neo4j.com)
9+
[![License](https://img.shields.io/pypi/l/neo4j-viz)](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.
615

7-
`neo4j-viz` is a Python package for creating interactive graph visualizations.
816
The package wraps the [Neo4j Visualization JavaScript library (NVL)](https://neo4j.com/docs/nvl/current/).
917

1018
Proper documentation is forthcoming.
1119

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.
1422
1523

1624
## Some notable features
@@ -39,8 +47,69 @@ This package is still in development and the API is subject to change.
3947
Please note that this list is by no means exhaustive.
4048

4149

42-
## Installation
50+
## Getting started
4351

44-
```
52+
53+
### Installation
54+
55+
Simply install with pip:
56+
57+
```sh
4558
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

Comments
 (0)