Skip to content

Commit f9b62ef

Browse files
authored
Merge pull request #119 from neo4j/simplify-neo4j-viz
Add convenience for Neo4j results
2 parents 5d205b1 + ee1150b commit f9b62ef

23 files changed

+400
-156
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Thank you for your contribution to the Graph Data Science Client project.
44
If relevant, link to the corresponding issue.
55
Please also include relevant motivation and context. List any dependencies that are required for this change. -->
66

7-
Before submitting this PR, please read [Contributing to the Neo4j Ecosystem](https://github.com/neo4j/nvl-python-wrapper/blob/main/CONTRIBUTING.md).
7+
Before submitting this PR, please read [Contributing to the Neo4j Ecosystem](https://github.com/neo4j/python-graph-visualization/blob/main/CONTRIBUTING.md).
88

99
Make sure:
1010
- [ ] You signed the [Neo4j CLA](https://neo4j.com/developer/cla/#sign-cla) (Contributor License Agreement) so that we are allowed to ship your code in our library

.github/workflows/unit-tests.yml

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
os: [ubuntu-latest]
26-
python-version: ["3.9", "3.10", "3.11", "3.12"]
26+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
2727

2828
defaults:
2929
run:
@@ -40,27 +40,8 @@ jobs:
4040
cache-dependency-path: pyproject.toml
4141
- run: pip install ".[dev]"
4242
- run: pip install ".[pandas]"
43+
- run: pip install ".[neo4j]"
4344
- run: pip install ".[gds]"
4445

4546
- name: Run tests
4647
run: pytest tests/
47-
48-
tests-313:
49-
runs-on: ubuntu-latest
50-
defaults:
51-
run:
52-
working-directory: python-wrapper
53-
steps:
54-
- uses: actions/checkout@v4
55-
56-
- uses: actions/setup-python@v5
57-
with:
58-
python-version: 3.13
59-
cache: 'pip'
60-
cache-dependency-path: pyproject.toml
61-
- run: pip install ".[dev]"
62-
- run: pip install ".[pandas]"
63-
# skip gds for now as it is not available for python 3.13
64-
65-
- name: Run tests
66-
run: pytest tests/

CONTRIBUTING.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,26 @@ pytest python-wrapper/tests
9494

9595
Additionally, there are integration tests that require an external data source.
9696
These require additional setup and configuration, such as environment variables specifying connection details.
97-
To run tests requiring a Neo4j DB instance with GDS installed, execute:
9897

98+
99+
For a local Neo4j instance with GDS installed, execute:
100+
```sh
101+
cd test-envs/neo4j-gds
102+
docker compose up -d
103+
```
104+
105+
To run tests requiring a Neo4j DB instance with GDS installed, execute:
99106
```sh
100-
pytest python-wrapper/tests --include-neo4j-and-gds
107+
export NEO4J_URI=localhost:7687 # or credentials for Aura API
108+
cd python-wrapper/
109+
pytest tests --include-neo4j-and-gds
101110
```
102111

103112
To run tests requiring a Snowflake connection, execute:
104113

105114
```sh
106-
pytest python-wrapper/tests --include-snowflake
115+
cd python-wrapper/
116+
pytest tests/ --include-snowflake
107117
```
108118

109119

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Proper documentation is forthcoming.
2727

2828
* Easy to import graphs represented as:
2929
* projections in the Neo4j Graph Data Science (GDS) library
30+
* graphs from Neo4j query results
3031
* pandas DataFrames
3132
* Node features:
3233
* Sizing

docs/source/adjusting.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ In this case, all nodes with the same caption will get the same color.
5151

5252
If there are fewer colors that unique values for the node ``property`` provided, the colors will be reused in a cycle.
5353
To avoid that, you could use another palette or extend one with additional colors. Please refer to the
54-
:doc:`Visualizing Neo4j Graph Data Science (GDS) Graphs tutorial <./tutorials/gds-nvl-example>` for an example on how
54+
:doc:`Visualizing Neo4j Graph Data Science (GDS) Graphs tutorial <./tutorials/gds-example>` for an example on how
5555
to do the latter.
5656

5757
If some nodes already have a ``color`` set, you can choose whether or not to override it with the ``override``
@@ -142,4 +142,4 @@ Each node and relationship has attributes that can be accessed and modified dire
142142
VG.nodes[0].size = 10
143143
VG.relationships[4].caption = "BUYS"
144144
145-
Any changes made to the nodes and relationships will be reflected in the next rendering of the graph.
145+
Any changes made to the nodes and relationships will be reflected in the next rendering of the graph.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Import from Neo4j
2+
------------------------------------------------
3+
4+
.. automodule:: neo4j_viz.neo4j
5+
:members:

docs/source/installation.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ To install the additional dependencies required for the :doc:`from_dfs importer
2424
2525
pip install neo4j-viz[pandas]
2626
27+
Neo4j ``from_neo4j`` importer
28+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29+
30+
To install the additional dependencies required for the :doc:`from_neo4j importer <./api-reference/from_neo4j>` you can run:
31+
32+
.. code-block:: bash
33+
34+
pip install neo4j-viz[neo4j]
35+
2736
2837
Neo4j Graph Data Science ``from_gds`` importer
2938
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

docs/source/integration.rst

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ and :doc:`Relationships <./api-reference/relationship>`.
6767
VG = from_dfs(nodes, relationships)
6868
6969
For another example of the ``from_dfs`` importer in action, see the
70-
:doc:`Visualizing Snowflake Tables tutorial <./tutorials/snowpark-nvl-example>`.
70+
:doc:`Visualizing Snowflake Tables tutorial <./tutorials/snowpark-example>`.
7171

7272

7373
Neo4j Graph Data Science (GDS) library
@@ -139,5 +139,67 @@ We use the "pagerank" property to determine the size of the nodes, and the "comp
139139
VG.color_nodes("componentId")
140140
141141
142-
Please see the :doc:`Visualizing Neo4j Graph Data Science (GDS) Graphs tutorial <./tutorials/gds-nvl-example>` for a
142+
Please see the :doc:`Visualizing Neo4j Graph Data Science (GDS) Graphs tutorial <./tutorials/gds-example>` for a
143+
more extensive example.
144+
145+
146+
Neo4j Database
147+
---------------
148+
149+
The ``neo4j-viz`` library provides a convenience method for importing data from Neo4j.
150+
It requires and additional dependency to be installed, which you can do by running:
151+
152+
.. code-block:: bash
153+
154+
pip install neo4j-viz[neo4j]
155+
156+
Once you have installed the additional dependency, you can use the :doc:`from_neo4j <./api-reference/from_neo4j>` method
157+
to import query results from Neo4j.
158+
159+
The ``from_neo4j`` method takes one mandatory positional parameters:
160+
161+
* A ``result`` representing the query result either in form of `neo4j.graph.Graph` or `neo4j.Result`.
162+
163+
The ``node_caption`` parameter is also optional, and indicates the value to use for the caption of each node in the visualization.
164+
165+
We can also provide an optional ``size_property`` parameter, which should refer to a node property of the projection,
166+
and will be used to determine the size of the nodes in the visualization.
167+
168+
The last optional property, ``node_radius_min_max``, can be used (and is used by default) to scale the node sizes for
169+
the visualization.
170+
It is a tuple of two numbers, representing the radii (sizes) in pixels of the smallest and largest nodes respectively in
171+
the visualization.
172+
The node sizes will be scaled such that the smallest node will have the size of the first value, and the largest node
173+
will have the size of the second value.
174+
The other nodes will be scaled linearly between these two values according to their relative size.
175+
This can be useful if node sizes vary a lot, or are all very small or very big.
176+
177+
178+
Example
179+
~~~~~~~
180+
181+
In this small example, we import a graph from a Neo4j query result.
182+
183+
.. code-block:: python
184+
185+
from neo4j import GraphDataScience
186+
from neo4j_viz.gds import from_gds
187+
188+
# Modify this to match your Neo4j instance's URI and credentials
189+
URI = "neo4j://localhost:7687"
190+
auth = ("neo4j", "password")
191+
192+
with GraphDatabase.driver(URI, auth=auth) as driver:
193+
driver.verify_connectivity()
194+
195+
result = driver.execute_query(
196+
"MATCH (n)-[r]->(m) RETURN n,r,m",
197+
database_="neo4j",
198+
result_transformer_=Result.graph,
199+
)
200+
201+
VG = from_neo4j(result)
202+
203+
204+
Please see the :doc:`Visualizing Neo4j Graphs tutorial <./tutorials/neo4j-example>` for a
143205
more extensive example.

docs/source/tutorials/gds-nvl-example.nblink renamed to docs/source/tutorials/gds-example.nblink

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"path": "../../../examples/gds-nvl-example.ipynb",
2+
"path": "../../../examples/gds-example.ipynb",
33
"extra-media": [
44
"../../../examples/example_cora_graph.png"
55
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"path": "../../../examples/neo4j-example.ipynb"
3+
}

0 commit comments

Comments
 (0)