Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- run: pip install ".[dev]"
- run: pip install ".[pandas]"
- run: pip install ".[gds]"
- run: pip install ".[snowflake]"

- name: Check code style
run: cd ${GITHUB_WORKSPACE} && ./scripts/checkstyle.sh
1 change: 1 addition & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
- run: pip install ".[pandas]"
- run: pip install ".[neo4j]"
- run: pip install ".[gds]"
- run: pip install ".[snowflake]"

- name: Run tests
run: pytest tests/
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

## New features

* Added new constructor `from_snowflake` that creates visualization graphs from Snowflake tables.


## Bug fixes


## Improvements

* The `field` parameter of `color_nodes` now also accepts casing other than `snake_case`.


## Other changes
6 changes: 6 additions & 0 deletions docs/source/api-reference/from_snowflake.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Import from Snowflake Tables
----------------------------

.. automodule:: neo4j_viz.snowflake
:members:
:exclude-members: Orientation, VizProjectConfig, VizRelationshipTableConfig
1 change: 0 additions & 1 deletion docs/source/api-reference/render_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
.. autoenum:: neo4j_viz.options.Packing
:members:


.. autoenum:: neo4j_viz.Renderer
:members:
5 changes: 3 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ The library allows you to visualize graph data interactively in Python using a s

The library wraps the `Neo4j Visualization JavaScript library (NVL) <https://neo4j.com/docs/nvl/current/>`_, and
provides additional features for working with graph data in Python.
Notably, there are convenience methods for importing data from `Pandas DataFrames <https://pandas.pydata.org/>`_,
`Neo4j Graph Data Science <https://neo4j.com/docs/graph-data-science/current/>`_ and `Neo4j Database <https://neo4j.com/docs/python-manual/current/>`_.
Notably, there are convenience methods for importing data from source such as `Pandas DataFrames <https://pandas.pydata.org/>`_,
`Neo4j Graph Data Science <https://neo4j.com/docs/graph-data-science/current/>`_, `Neo4j Database <https://neo4j.com/docs/python-manual/current/>`_
and `Snowflake tables <https://docs.snowflake.com/>`_.

The source code is available on `GitHub <https://github.com/neo4j/python-graph-visualization>`_.
If you have a suggestion on how we can improve the library or want to report a problem, you can create a `new issue <https://github.com/neo4j/python-graph-visualization/issues/new>`_.
Expand Down
14 changes: 13 additions & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ To install the additional dependencies required for the :doc:`from_dfs importer

pip install neo4j-viz[pandas]


Neo4j ``from_neo4j`` importer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To install the additional dependencies required for the :doc:`from_neo4j importer <./api-reference/from_neo4j>` you can run:

Expand All @@ -43,6 +44,17 @@ To install the additional dependencies required for the :doc:`from_gds importer

pip install neo4j-viz[gds]


Snowflake tables ``from_snowflake`` importer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To install the additional dependencies required for the :doc:`from_snowflake importer <./api-reference/from_snowflake>` you can run:

.. code-block:: bash

pip install neo4j-viz[snowflake]


Notebook tutorials
~~~~~~~~~~~~~~~~~~

Expand Down
135 changes: 126 additions & 9 deletions docs/source/integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ In addition to creating graphs from scratch, with ``neo4j-viz`` as is shown in t
:doc:`Getting started section <./getting-started>`, you can also import data directly from external sources.
In this section we will cover how to import data from `Pandas DataFrames <https://pandas.pydata.org/>`_,
`Neo4j Graph Data Science <https://neo4j.com/docs/graph-data-science/current/>`_,
`Neo4j Database <https://neo4j.com/docs/python-manual/current/>`_ and
`GQL CREATE queries <https://neo4j.com/docs/cypher-manual/current/clauses/create/>`_.
`Neo4j Database <https://neo4j.com/docs/python-manual/current/>`_,
`GQL CREATE queries <https://neo4j.com/docs/cypher-manual/current/clauses/create/>`_,
and `Snowflake tables <https://docs.snowflake.com/>`_.


.. contents:: On this page:
Expand All @@ -19,14 +20,14 @@ Pandas DataFrames
-----------------

The ``neo4j-viz`` library provides a convenience method for importing data from Pandas DataFrames.
These DataFrames can be created from many sources, such as CSV files or :doc:`Snowflake tables<./tutorials/snowpark-example>`.
These DataFrames can be created from many sources, such as CSV files.
It requires and additional dependency to be installed, which you can do by running:

.. code-block:: bash

pip install neo4j-viz[pandas]

Once you have installed the additional dependency, you can use the :doc:`from_gds <./api-reference/from_pandas>` method
Once you have installed the additional dependency, you can use the :doc:`from_pandas <./api-reference/from_pandas>` method
to import pandas DataFrames.

The ``from_dfs`` method takes two mandatory positional parameters:
Expand Down Expand Up @@ -82,9 +83,6 @@ and :doc:`Relationships <./api-reference/relationship>`.

VG = from_dfs(nodes, relationships)

For another example of the ``from_dfs`` importer in action, see the
:doc:`Visualizing Snowflake Tables tutorial <./tutorials/snowpark-example>`.


Neo4j Graph Data Science (GDS) library
--------------------------------------
Expand Down Expand Up @@ -118,9 +116,9 @@ and will be used to determine the sizes of the nodes in the visualization.

The ``additional_node_properties`` parameter is also optional, and should be a list of additional node properties of the
projection that you want to include in the visualization.
The default is `None`, which means that all properties of the nodes in the projection will be included.
The default is ``None``, which means that all properties of the nodes in the projection will be included.
Apart from being visible through on-hover tooltips, these properties could be used to color the nodes, or give captions
to them in the visualization, or simply included in the nodes' `Node.properties` maps without directly impacting the
to them in the visualization, or simply included in the nodes' ``Node.properties`` maps without directly impacting the
visualization.

The last optional property, ``node_radius_min_max``, can be used (and is used by default) to scale the node sizes for
Expand Down Expand Up @@ -285,3 +283,122 @@ In this small example, we create a visualization graph from a GQL ``CREATE`` que
"""

VG = from_gql_create(query)


Snowflake Tables
----------------

The ``neo4j-viz`` library provides a convenience method for importing data from Snowflake tables.
It requires and additional dependency to be installed, which you can do by running:

.. code-block:: bash

pip install neo4j-viz[snowflake]

Once you have installed the additional dependency, you can use the :doc:`from_snowflake <./api-reference/from_snowflake>` method
to import Snowflake tables into a ``VisualizationGraph``.

The ``from_snowflake`` method takes two mandatory positional parameters:

* A ``snowflake.snowpark.Session`` object for the connection to Snowflake, and
* A `project configuration <https://neo4j.com/docs/snowflake-graph-analytics/current/jobs/#jobs-project>`_ as a dictionary, that specifies how you want your tables to be projected as a graph.
This configuration is the same as the project configuration of the `Neo4j Snowflake Graph Analytics application <https://neo4j.com/docs/snowflake-graph-analytics/current/>`_.

``from_snowflake`` also takes an optional property, ``node_radius_min_max``, that can be used (and is used by default) to
scale the node sizes for the visualization.
It is a tuple of two numbers, representing the radii (sizes) in pixels of the smallest and largest nodes respectively in
the visualization.
The node sizes will be scaled such that the smallest node will have the size of the first value, and the largest node
will have the size of the second value.
The other nodes will be scaled linearly between these two values according to their relative size.
This can be useful if node sizes vary a lot, or are all very small or very big.


Special columns
~~~~~~~~~~~~~~~

It is possible to modify the visualization directly by including columns of certain specific names in the node and relationship tables.

All such special columns can be found :doc:`here <./api-reference/node>` for nodes and :doc:`here <./api-reference/relationship>` for relationships.
Though listed in ``snake_case`` here, ``SCREAMING_SNAKE_CASE`` and ``camelCase`` are also supported.
Some of the most commonly used special columns are:

* **Node sizes**: The sizes of nodes can be controlled by including a column named "SIZE" in node tables.
The values in these columns should be of a numeric type. This can be useful for visualizing the relative importance or size of nodes in the graph, for example using a computed centrality score.

* **Captions**: The caption text of nodes and relationships can be controlled by including a column named "CAPTION" in the tables.
The values in these columns should be of a string type. This can be useful for displaying additional information about the nodes, such as their names or labels. If no "CAPTION" column is provided, the default captions in the visualization will be the names of the corresponding node and relationship tables.

Please also note that you can further customize the visualization after the `VisualizationGraph` has been created, by using the methods described in the :doc:`Customizing the visualization <./customizing>` section.


Default behavior
~~~~~~~~~~~~~~~~

Unless there are "CAPTION" columns in the tables, the node and relationship captions will be set to the names of the corresponding tables.
Similarly, if there are are no "COLOR" node table columns, the nodes will be colored be colored so that nodes from the same table have the same color, and different tables have different colors.


Example
~~~~~~~

In this small example, we import a toy graph representing a social network from two tables in Snowflake.

.. code-block:: python

from snowflake.snowpark import Session
from neo4j_viz.snowflake import from_dfs

# Configure according to your own setup
connection_parameters = {
"account": os.environ.get("SNOWFLAKE_ACCOUNT"),
"user": os.environ.get("SNOWFLAKE_USER"),
"password": os.environ.get("SNOWFLAKE_PASSWORD"),
"role": os.environ.get("SNOWFLAKE_ROLE"),
"warehouse": os.environ.get("SNOWFLAKE_WAREHOUSE"),
}

session.sql(
"CREATE OR REPLACE TABLE EXAMPLE_DB.DATA_SCHEMA.PERSONS (NODEID VARCHAR);"
).collect()

session.sql("""
INSERT INTO EXAMPLE_DB.DATA_SCHEMA.PERSONS VALUES
('Alice'),
('Bob'),
('Carol'),
('Dave'),
('Eve');
""").collect()

session.sql(
"CREATE OR REPLACE TABLE EXAMPLE_DB.DATA_SCHEMA.KNOWS (SOURCENODEID VARCHAR, TARGETNODEID VARCHAR);"
).collect()

session.sql("""
INSERT INTO EXAMPLE_DB.DATA_SCHEMA.KNOWS VALUES
('Alice', 'Dave'),
('Alice', 'Carol'),
('Bob', 'Carol'),
('Dave', 'Eve'),
""").collect()

VG = from_snowflake(
session,
{
"nodeTables": [
"EXAMPLE_DB.DATA_SCHEMA.PERSONS",
],
"relationshipTables": {
"EXAMPLE_DB.DATA_SCHEMA.KNOWS": {
"sourceTable": "EXAMPLE_DB.DATA_SCHEMA.PERSONS",
"targetTable": "EXAMPLE_DB.DATA_SCHEMA.PERSONS",
"orientation": "UNDIRECTED",
}
},
},
)

For a full example of the ``from_snowflake`` importer in action, please see the
:doc:`Visualizing Snowflake Tables tutorial <./tutorials/snowflake-example>`.

3 changes: 3 additions & 0 deletions docs/source/tutorials/snowflake-example.nblink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "../../../examples/snowflake-example.ipynb"
}
3 changes: 0 additions & 3 deletions docs/source/tutorials/snowpark-example.nblink

This file was deleted.

Loading