Skip to main content

🐍 neo4jvis

Installation

Neo4jvis requires Neo4j driver. You can install neo4jvis with:

pip install neo4jvis

Usage

Here's how you can use it: First import libraries, initialise the driver and create the graph container:

1. Import and init

from neo4j import GraphDatabase
from neo4jvis.model.styled_graph import StyledGraph

driver = GraphDatabase.driver(uri="bolt://url:port", auth=("my user", "my pass"))
graph = StyledGraph(driver)

2. Retrieve graph from neo4j

2.1 Retrieve whole graph

Here's how you can generate an html file with all the nodes and relationships of the database:

graph.generate_whole_graph()
graph.draw("output.html")

2.2 Generate graph from a query

Here's is how you can generate a graph from a given query provided by the developer:

QUERY = "MATCH p=()-[]->() RETURN p"

graph.add_from_query(QUERY)
graph.draw("output.html")

3. Style graph

3.1 Change nodes color

RED = "#ff0000"
WHITE = "#FFFFFF"

for node in list(graph.nodes.values()):
    node["color"] = {
        "border": WHITE,
        "background": RED
    }
graph.draw("output.html")

3.2 Change nodes size

for node in list(graph.nodes.values()):
    node["value"] = randrange(1, 10)
graph.draw("output.html")

3.3. Change other node properties supported by vis.js

Neo4jvis supports all the options for nodes of vis.js.

Example usage:

node["shape"] = "triangle"
node["borderWidth"] = 10
node["label"] = "EXAMPLE"
node["font"] = {
    "color": "#e8c2b0",
    "size": 20,
}
graph.draw("output.html")

3.4. Change edge properties

for edge in graph.edges:
    edge["value"] = random.randrange(1, 10)
    edge["color"] = {
        "color": "#e8c2b0"
    }
graph.draw("output.html")

3.5. Change other edge properties

Similarly, as with nodes, neo4jvis supports all the options for edges of vis.js.

4. Change graph options

Graphs come with a default set of options defined in options property:

>>> print(graph.options)
{
    'nodes': ...
    'edges': ...
    'interaction': ...
    'physics': ...
}

See the available options for graphs supported by vis.js.

Example usage:

graph.options["directed"] = "false"

Advanced usage

Generate graph from neomodel StructuredRel

Neomodel is a Object Graph Mapper for Neo4j database. Neo4jvis allows the retrieval of the network from a list of neomodel StructuredRel objects. Here's an example of the usage:

class Connected(StructuredRel):
    pass

class Usuarios(StructuredNode):
    id = StringProperty()
    connected = RelationshipTo("Usuarios", "CONNECTED", model = Connected)

QUERY = """ 
    MATCH (n1:Usuarios)-[r:CONNECTED]->() 
    RETURN r
"""

Z = neomodel.db.cypher_query(
    QUERY, 
    resolve_objects=True)
relationships_list = [rel[0] for rel in Z[0]]    
graph.add_from_neomodel_relationships(relationships_list)
graph.draw("output.html")

Release files for neo4jvis 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for neo4jvis 0.0.1
File Size Uploaded
neo4jvis-0.0.1.tar.gz 155.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for neo4jvis 0.0.1
File Interpreter ABI Platform
neo4jvis-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 167.0 kB

Release files / neo4jvis-0.0.1.tar.gz

Download URL neo4jvis-0.0.1.tar.gz
Size 155.0 kB
Tags Source
SHA-256 checksum
How to use checksums
119e7177f8d4966f8eb74df5937fda00f9e110f50358b473835956729c70b342
BLAKE2b-256 checksum
How to use checksums
d200304f937603235c5f80c78c7bcba385bec6ab435594fc62d983371efccce5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.12

Release files / neo4jvis-0.0.1-py3-none-any.whl

Download URL neo4jvis-0.0.1-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b10fe0e15c5197c0a0e7a7c8f5775142783992ef37c886229579f3f8b910d3f
BLAKE2b-256 checksum
How to use checksums
3b9e0042b01dae1d8925e1e0a3c6d2e979d3e23dba576dc9ba74dd1e2f225bcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.12
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page