Giter VIP home page Giter VIP logo

networkx-neo4j's Introduction

networkx-neo4j

This library provides NetworkX API for Neo4j Graph Data Science. You should be able to use it as you would NetworkX but algorithms will run against Neo4j.

Dependencies

  • ≥ Neo4j 4.x

  • Graph Data Science Library Plugin

  • APOC Plugin

  • ≥ Python 3.6

  • ≥ neo4j-driver 4.x

Installation

You can install the library by running the following command:

pip install networkx-neo4j

You’ll also need to install APOC and the Graph Algorithms library.

plugin gds

Usage

Here’s how you use it.

First let’s import our libraries and create an instance of the Neo4j driver:

>>> from neo4j import GraphDatabase
>>> import nxneo4j as nx

>>> driver = GraphDatabase.driver(uri="bolt://localhost",auth=("neo4j","your_password"))

For undirected Graphs:

>>> G = nx.Graph(driver)

For directed Graphs:

>>> G = nx.DiGraph(driver)

The available functions in nxneo4j are:

# ADD ONE NODE
G.add_node(node)
node: str, int
>>> G.add_node(1)

# ADD MULTIPLE NODES
G.add_nodes_from(value)
values: list
>>> G.add_nodes_from([1, 2, 3, 4])

# ADD ONE EDGE
G.add_edge(node1,node2)
node1: str, int
node2: str, int
>>> G.add_edge(1,2)

#ADD MULTIPLE EDGES
G.add_edges_from(values)
values: list of tuples
>>> G.add_edges_from([(1, 2),(2, 3),(3, 4)])

The available algoritms in nxneo4j are:

>>> nx.betweenness_centrality(G)
{3: 4.0, 4: 3.0, 1: 0.0, 2: 0.0, 5: 0.0}

>>> nx.closeness_centrality(G)
{3: 0.8, 4: 0.6666666666666666, 1: 0.5714285714285714, 2: 0.5714285714285714, 5: 0.4444444444444444}

>>> nx.pagerank(G)
{3: 1.4170146573314513, 4: 1.0629939728840803, 1: 0.9591085771210682, 2: 0.9591085771210682, 5: 0.6017724112363687}

>>> nx.triangles(G)
{1: 1, 2: 1, 3: 1, 4: 0, 5: 0}

>>> nx.clustering(G)
{1: 1.0, 2: 1.0, 3: 0.3333333333333333, 4: 0.0, 5: 0.0}

>>> list(nx.community.label_propagation_communities(G))
[{1, 2, 3, 4, 5}]

>>> nx.shortest_path(G, source=1, target=5)
[1, 3, 4, 5]

Credits

Yusuf Baktir Mark Needham David Jablonski

networkx-neo4j's People

Contributors

mneedham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.