A Python wrapper API for operating and working with the Neo4j Graph Data Science (GDS) library

Overview

gdsclient

NOTE: This is a work in progress and many GDS features are known to be missing or not working properly.

This repo hosts the sources for gdsclient, a Python wrapper API for operating and working with the Neo4j Graph Data Science (GDS) library. gdsclient enables users to write pure Python code to project graphs, run algorithms, and define and use machine learning pipelines in GDS. The API is designed to mimic the GDS Cypher procedure API, but in Python code. It abstracts the necessary operation of the Neo4j Python Driver to offer a simpler surface.

Please leave any feedback as issues on this repository. Happy coding!

Installation

To build and install gdsclient from this repository, simply run the following command:

pip3 install .

Documentation

A minimal example of using gdsclient to connect to a Neo4j database and run GDS algorithms:

from neo4j import GraphDatabase
from gdsclient import Neo4jQueryRunner, GraphDataScience

# Set up driver and gds module
URI = "bolt://localhost:7687" # Override according to your setup
driver = GraphDatabase.driver(URI) # You might also have auth set up in your db
runner = Neo4jQueryRunner(driver)
gds = GraphDataScience(runner)

# Project your graph
graph = gds.graph.create("graph", "*", "*")

# Run the PageRank algorithm with custom configuration
gds.pageRank.write(graph, tolerance=0.5, writeProperty="pagerank")

For extensive documentation of all operations supported by GDS, please refer to the GDS Manual.

Extensive end-to-end examples in Jupyter ready-to-run notebooks can be found in the examples directory:

Acknowledgements

This work has been inspired by the great work done in the following libraries:

Contributing

The gdsclient project does not yet have contribution guidelines.

License

See LICENSE file. All content is copyright © Neo4j Sweden AB.

Comments
  • streamNodeProperty() doesn't work with gds.run_cypher() as I guess

    streamNodeProperty() doesn't work with gds.run_cypher() as I guess

    graphdatascience 1.3

    I tried a query like this:

    query = f'''
       call gds.graph.streamNodeProperty(
          'xxx',
          'xxxx',
          ['xxxxx']
       )
    yield nodeId as id, propertyValue as degree
    return id, degree limit 100
    ...
    result = gds.run_cypher(query)
    

    => KeyError: 'graph_name'

    I figured out to make it work like this:

    query = f'''
       ...
    '''
    params = {
       'graph_name': 'xxx',
       'properties': 'xxxx',
       'entities'" ['xxxxx'],
       'config': ''
    }
    result = gds.run_cypher(query, params)
    

    => No error, but it returned all rows(not limited to 100) as nodeId and propertyValue(not renamed as id and degree)

    Other cypher queries works with gds.run_cypher(query) as expected.

    opened by MOSSupport 27
  • Add IMDB data and loaders

    Add IMDB data and loaders

    Co-authored-by: Adam Schill Collberg [email protected]

    Thank you for your contribution to the Graph Data Science Client project.

    Before submitting this PR, please read Contributing to the Neo4j Ecosystem.

    Make sure:

    • [x] You signed the Neo4j CLA (Contributor License Agreement) so that we are allowed to ship your code in our library
    • [x] Your contribution is covered by tests
    REVIEW OK - MERGE ON HOLD 
    opened by brs96 10
  • Skip defaults tests when targeting AuraDS

    Skip defaults tests when targeting AuraDS

    Since the "neo4j" user lacks auth there.

    Thank you for your contribution to the Graph Data Science Client project.

    Before submitting this PR, please read Contributing to the Neo4j Ecosystem.

    Make sure:

    • [ ] You signed the Neo4j CLA (Contributor License Agreement) so that we are allowed to ship your code in our library
    • [ ] Your contribution is covered by tests
    opened by adamnsch 5
  • gds.degree.stream not respecting orientation?

    gds.degree.stream not respecting orientation?

    Describe the bug I'm trying to reproduce a similar result that I would get in GDS.

    To Reproduce Cypher code:

    call gds.graph.project('xdc-test-search', ['Event','Search'], { HAS_SEARCH:{orientation:'REVERSE'}})
    call gds.degree.stream('xdc-test-search')
    YIELD nodeId, score
    return gds.util.asNode(nodeId).search_name_1 as SearchTerm, score As NumberOfSearches
    Order by NumberOfSearches Descending, SearchTerm Limit 10;
    

    The above returns the Search nodes.

    Python code:

    node_projection = ["Event","Search"]
    relationship_projection = {"HAS_SEARCH": {"orientation": "REVERSE"}}
    G, _ = gds.graph.project("xdc-test-search", node_projection, relationship_projection)
    degree_stream = gds.degree.stream(G)
    

    degree.stream above is returning the node ids of the Event nodes (other side of direction), even if I were to use G = gds.graph.get("xdc-test-search") and use the projection created with cypher.

    I'm sure it's something I'm doing on my end :)

    graphdatascience library version: 1.3 GDS plugin version: 2.1.7 Python version: 3.9.12 Neo4j version: 4.4.10 Operating system: macOS 12.6

    The image below is what I would expect from the python approach. image

    opened by bSharpCyclist 4
  • Support multiple dataframe input to CE construct

    Support multiple dataframe input to CE construct

    Thank you for your contribution to the Graph Data Science Client project.

    Before submitting this PR, please read Contributing to the Neo4j Ecosystem.

    Make sure:

    • [x] You signed the Neo4j CLA (Contributor License Agreement) so that we are allowed to ship your code in our library
    • [x] Your contribution is covered by tests
    opened by adamnsch 3
  • Expose undirected rel types in graph.construct and load_cora

    Expose undirected rel types in graph.construct and load_cora

    Thank you for your contribution to the Graph Data Science Client project.

    Before submitting this PR, please read Contributing to the Neo4j Ecosystem.

    Make sure:

    • [x] You signed the Neo4j CLA (Contributor License Agreement) so that we are allowed to ship your code in our library
    • [x] Your contribution is covered by tests
    opened by FlorentinD 3
  • Test graph.construct with nan properties

    Test graph.construct with nan properties

    • Enable arrow test against AuraDS
    • Test NaN and null handling in graph.construct

    Thank you for your contribution to the Graph Data Science Client project.

    Before submitting this PR, please read Contributing to the Neo4j Ecosystem.

    Make sure:

    • [x] You signed the Neo4j CLA (Contributor License Agreement) so that we are allowed to ship your code in our library
    • [x] Your contribution is covered by tests
    opened by FlorentinD 3
  • Handle gds.alpha.graph.nodeLabel.write

    Handle gds.alpha.graph.nodeLabel.write

    Thank you for your contribution to the Graph Data Science Client project.

    Before submitting this PR, please read Contributing to the Neo4j Ecosystem.

    Make sure:

    • [ ] You signed the Neo4j CLA (Contributor License Agreement) so that we are allowed to ship your code in our library
    • [ ] Your contribution is covered by tests
    opened by vnickolov 3
  • Relationship Orientation during graph construction with dataframes

    Relationship Orientation during graph construction with dataframes

    Hi, I'd like to understand if it is possible to construct a graph from data frames without orientation so that I can have an undirected relationship. I see from the schema here https://neo4j.com/docs/graph-data-science/current/graph-project-apache-arrow/#arrow-send-relationships that source and destination are mandatory but there is no special column for orientation.

    opened by valerio-piccioni 3
  • Add mapping for `gds.alpha.triangles`

    Add mapping for `gds.alpha.triangles`

    Thank you for your contribution to the Graph Data Science Client project.

    Before submitting this PR, please read Contributing to the Neo4j Ecosystem.

    Make sure:

    • [x] You signed the Neo4j CLA (Contributor License Agreement) so that we are allowed to ship your code in our library
    • [x] Your contribution is covered by tests
    opened by FlorentinD 3
  • Set target database within initial constructor call

    Set target database within initial constructor call

    Is your feature request related to a problem? Please describe. I would like to set the database I plan to use upon initializing my gds object GraphDataScience(URI, auth=creds, database='my-db') rather than having to call gds.set_database("my-db"). This would purely be a simple convenience to save a line of code.

    Describe the solution you would like Allow the setting of the database within the constructor call

    opened by seankrobinson 3
  • Throw better warning if construct is called multiple times

    Throw better warning if construct is called multiple times

    This improves the UX for beginners who accidentally call f.i. gds.graph.load_cora twice without cleanup.

    Thank you for your contribution to the Graph Data Science Client project.

    Before submitting this PR, please read Contributing to the Neo4j Ecosystem.

    Make sure:

    • [x] You signed the Neo4j CLA (Contributor License Agreement) so that we are allowed to ship your code in our library
    • [x] Your contribution is covered by tests
    opened by FlorentinD 2
  • WIP: Hashgnn example notebook

    WIP: Hashgnn example notebook

    Based on #224

    Thank you for your contribution to the Graph Data Science Client project.

    Before submitting this PR, please read Contributing to the Neo4j Ecosystem.

    Make sure:

    • [ ] You signed the Neo4j CLA (Contributor License Agreement) so that we are allowed to ship your code in our library
    • [ ] Your contribution is covered by tests
    opened by adamnsch 1
  • Add convenience methods for loading OGB graphs

    Add convenience methods for loading OGB graphs

    Thank you for your contribution to the Graph Data Science Client project.

    Before submitting this PR, please read Contributing to the Neo4j Ecosystem.

    Make sure:

    • [ ] You signed the Neo4j CLA (Contributor License Agreement) so that we are allowed to ship your code in our library
    • [ ] Your contribution is covered by tests
    opened by adamnsch 1
  • WIP: Update query runner interface

    WIP: Update query runner interface

    Thank you for your contribution to the Graph Data Science Client project.

    Before submitting this PR, please read Contributing to the Neo4j Ecosystem.

    Make sure:

    • [ ] You signed the Neo4j CLA (Contributor License Agreement) so that we are allowed to ship your code in our library
    • [ ] Your contribution is covered by tests
    opened by adamnsch 1
Releases(1.5)
  • 1.5(Nov 2, 2022)

    We are happy to announce the release of graphdatascience, the GDS Python client, version 1.5! It is published to PyPI!

    Changes:

    • Fixed a bug where the client could not connect to the server when the default db was set in the GraphDataScience constructor.
    • For GDS admin users, gds.graph.get is now able to resolve graph names into Graph objects of other users graph projections.
    • Add support for gds.alpha.triangles.
    • Support calling gds.alpha.userLog to access hints and warnings for the recently run operations.
    • Add support for gds.alpha.backup and gds.alpha.restore.
    • Add support for gds.alpha.config.defaults.set and gds.alpha.config.defaults.list.

    The release can be pip installed with pip install graphdatascience==1.5.

    Source code(tar.gz)
    Source code(zip)
  • 1.4(Sep 30, 2022)

    We are happy to announce the release of graphdatascience, the GDS Python client, version 1.4! It is published to PyPI!

    Highlights:

    • The DataFrame returned by gds.beta.graph.relationships.stream now has a convenience method called by_rel_type.
    • Added a new optional string parameter database to GraphDataScience.run_cypher for overriding which database to target.
    • Added new method gds.graph.load_cora to load the CORA dataset into GDS.
    • Added a new optional string parameter database to the GraphDataScience constructor for specifying the targeted database.
    • Fix resolving Node regression pipelines created via gds.alpha.pipeline.nodeRegression.create.
    • Fix resolving Node regression models created via gds.alpha.pipeline.nodeRegression.train.
    • Fix an issue where run_cypher did not execute Cypher correctly in some edge cases.

    A full list of changes can be found in the changelog.

    The release can be pip installed with pip install graphdatascience==1.4.

    Source code(tar.gz)
    Source code(zip)
  • 1.3(Aug 23, 2022)

    We are happy to announce the release of graphdatascience, the GDS Python client, version 1.3! It is published to PyPI!

    Highlights:

    • New versioning scheme using only two numbers
    • Add MLP training method addMLP to link prediction and node classification pipelines.
    • Add support for new graph catalog API endpoints in GDS >= 2.2.0.
    • Add support for random walk with restarts sampling procedure.
    • Add support for graph property endpoints in GDS >= 2.2.0.
    • Add Arrow Flight specific parameters to the GraphDataScience constructor:
      • arrow_tls_root_certs
      • arrow_disable_server_verification
    • Add support for new stream graph relationships endpoint.
    • Dropped support for Python 3.6.

    A full list of changes can be found in the changelog.

    The release can be pip installed with pip install graphdatascience==1.3.

    Source code(tar.gz)
    Source code(zip)
  • 1.3.0a1(Aug 11, 2022)

    The first alpha release of version 1.3.0 of graphdatascience, the GDS Python client, has been published to PyPI!

    Highlights:

    • Add MLP training method addMLP to link prediction and node classification pipelines.
    • Add support for new graph catalog API endpoints in GDS >= 2.2.0.
    • Add support for random walk with restarts sampling procedure.
    • Add support for graph property endpoints in GDS >= 2.2.0.
    • Add Arrow Flight specific parameters to the GraphDataScience constructor:
      • arrow_tls_root_certs
      • arrow_disable_server_verification
    • Add support for new stream graph relationships endpoint.
    • Dropped support for Python 3.6.

    A full list of changes can be found in the changelog.

    The release can be pip installed with pip install graphdatascience==1.3.0a1.

    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Jul 5, 2022)

    Version 1.2.0 of graphdatascience, the GDS Python client, has been published to PyPI!

    Included are bug fixes for:

    • The separate_property_columns=True option of gds.graph.streamNodeProperties did not handle list node properties correctly.
    • An irrelevant warning was shown when creating a GraphDataScience object targeting an AuraDS instance with GDS server version >= 2.1.0.
    • Calling gds.alpha.graph.construct targeting an AuraDS instance would raise an exception.

    The release can be pip installed with pip install graphdatascience==1.2.0.

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Jun 9, 2022)

    Version 1.1.0 of graphdatascience, the GDS Python client, has been published to PyPI!

    Changes highlights:

    • Support for GDS library version 2.1
    • Additional and improved convenience functionality on the Graph object
    • Supporting GDS Apache Arrow capabilities for graph catalog stream procedures
    • New method gds.alpha.graph.construct for loading a graph directly into GDS from client side pandas DataFrames
      • Greatly sped up by Apache Arrow if enabled

    A full list of changes can be found in the changelog.

    The release can be pip installed with pip install graphdatascience==1.1.0.

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0rc1(Jun 2, 2022)

    The first release candidate of version 1.1.0 of graphdatascience, the GDS Python client, has been published to PyPI!

    Highlights:

    • Added support for auto tuning for machine learning pipelines.
    • Added support for providing ranges as length two tuples to addLogisticRegression and addRandomForest.
    • Added support for new GDS library 2.1 signature of gds.graph.removeNodeProperties.
    • Added support for new function gds.close which calls .close() on a GraphDataScience object's underlying Neo4j driver.
    • Added new method gds.alpha.graph.construct to construct a GDS graph from pandas DataFrames. When running against a GDS library with its Apache Arrow server enabled it will be a lot faster.
    • Added support for new nodeRegression pipelines.
    • New convenience methods on the Graph object.

    A full list of changes can be found in the changelog.

    The release can be pip installed with pip install graphdatascience==1.1.0rc1.

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0a2(May 19, 2022)

    The second alpha release of version 1.1.0 of graphdatascience, the GDS Python client, has been published to PyPI!

    Highlights:

    • Added support for new configureAutoTuning method on NC and LP pipelines.
    • Added support for providing ranges as length two tuples to addLogisticRegression and addRandomForest.
    • Added new method auto_tuning_config to NC and LP pipelines for querying a pipelines auto-tuning config.
    • Added support for new GDS library 2.1 signature of gds.graph.removeNodeProperties.
    • Added support for new function gds.close which calls .close() on a GraphDataScience object's underlying Neo4j driver.
    • Added new method gds.alpha.graph.construct to construct a GDS graph from pandas DataFrames, which works if the GDS Flight server is enabled.
    • Added new function gds.database which can be used to see which database is currently being targeted.
    • Added support for new nodeRegression pipelines.

    The release can be pip installed with pip install graphdatascience==1.1.0a2.

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0a1(May 6, 2022)

    The alpha release of version 1.1.0 of graphdatascience, the GDS Python client, has been published to PyPI!

    Highlights:

    • Added support for new configureAutoTuning method on NC and LP pipelines.
    • Added support for providing ranges as length two tuples to addLogisticRegression and addRandomForest.
    • Added support for new function gds.close which calls .close() on a GraphDataScience object's underlying Neo4j driver.
    • Added new method gds.alpha.graph.construct to construct a GDS graph from pandas DataFrames, which works if the GDS Flight server is enabled.
    • Added new function gds.database which can be used to see which database is currently being targeted.
    • The functions gds.graph.streamNodeProperty and gds.graph.streamRelationshipProperty can leverage the Arrow Flight server of GDS to improve throughput.

    The release can be pip installed with pip install graphdatascience==1.1.0a1.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Mar 24, 2022)

    The first official major release, 1.0.0, of graphdatascience, the GDS Python client, has been published to PyPI!

    Highlights:

    • Replaced all dict return types with pandas Series.
    • Replaced all list[dict,...] return types with pandas DataFrame.
    • Replaced NC and LP training pipelines method configureParams by new methods addLogisticRegression and addRandomForest.
    • All procedures of the GDS Pipeline catalog are supported.
    • The NC and LP training pipelines support estimating train via a train_estimate method.
    • All ML models support estimating predict via predict_[mode]_estimate methods.
    • Removed support for GDS 1.x graph.create syntax.

    Read more in the changelog.

    The release can be pip installed with pip install graphdatascience==1.0.0.

    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Feb 25, 2022)

    A new release 0.1.0 of graphdatascience, the GDS Python client, has been published at PyPI!

    Highlights:

    • When connecting to AuraDS, a specific user-agent will be set indicating that the graphdatascience client is used.
    • The methods of NCTrainingPipeline and LPTrainingPipeline for building the pipelines now return metadata from the underlying Cypher procedures called.
    • Methods creating Graph objects now additionally return the metadata from the underlying Cypher procedures called.
    • Methods creating Model objects now additionally return the metadata from the underlying Cypher procedures called.

    Read more in the changelog.

    The release can be pip installed with pip install graphdatascience==0.1.0.

    Source code(tar.gz)
    Source code(zip)
  • 0.0.9(Feb 3, 2022)

  • 0.0.8(Jan 24, 2022)

    A new release 0.0.8 of graphdatascience, which is the new and final name of the GDS Python client, formerly called gdsclient , has been published at PyPI!

    Highlights:

    • new library name!
    • new source repository (this repo)
    • support for all utility functions
    • support for all Similarity functions
    • simplified interface to construct GDS reference object (hidden driver)
    • simplified interface to run Cypher queries (hidden query runner)

    The release can be pip installed with pip install graphdatascience==0.0.8.

    Source code(tar.gz)
    Source code(zip)
Owner
Neo4j
Neo4j
This library is an ongoing effort towards bringing the data exchanging ability between Java/Scala and Python

PyJava This library is an ongoing effort towards bringing the data exchanging ability between Java/Scala and Python

Byzer 6 Oct 17, 2022
pyshell is a Linux subprocess module

pyshell A Linux subprocess module, An easier way to interact with the Linux shell pyshell should be cross platform but has only been tested with linux

4 Mar 02, 2022
Scripts to convert the Ted-MDB corpora into the formats for DISRPT shared task and the converted corpora

Scripts to convert the Ted-MDB corpora into the formats for DISRPT shared task and the converted corpora.

1 Feb 08, 2022
Allows you to purge all reply comments left by a user on a YouTube channel or video.

YouTube Spammer Purge Allows you to purge all reply comments left by a user on a YouTube channel or video. Purpose Recently, there has been a massive

4.3k Jan 09, 2023
Spooky Castle Project

Spooky Castle Project Here is a repository where I have placed a few workflow scripts that could be used to automate the blender to godot sprite pipel

3 Jan 17, 2022
A ULauncher/Albert extension that supports currency, units and date time conversion, as well as a calculator that supports complex numbers and functions.

Ulauncher/Albert Calculate Anything Ulauncher/Albert Calculate Anything is an extension for Ulauncher and Albert to calculate things like currency, ti

tchar 67 Jan 01, 2023
Lightweight library for accessing data and configuration

accsr This lightweight library contains utilities for managing, loading, uploading, opening and generally wrangling data and configurations. It was ba

appliedAI Initiative 7 Mar 09, 2022
Programa que organiza pastas automaticamente

📂 Folder Organizer 📂 Programa que organiza pastas automaticamente Requisitos • Como usar • Melhorias futuras • Capturas de Tela Requisitos Antes de

João Victor Vilela dos Santos 1 Nov 02, 2021
Um pequeno painel de consulta

Spynel Um pequeno painel com consultas de: IP CEP PLACA CNPJ OBS: caso execute o script pelo termux, recomendo que use o da F-Droid por ser mais atual

Spyware 12 Oct 25, 2022
Entitlement AND Hardened Runtime Check

Python3 script for macOS to recursively check /Applications and also check /usr/local/bin, /usr/bin, and /usr/sbin for binaries with problematic/interesting entitlements. Also checks for hardened run

Cedric Owens 79 Nov 16, 2022
A Klipper plugin for accurate Z homing

Stable Z Homing for Klipper A Klipper plugin for accurate Z homing This plugin provides a new G-code command, STABLE_Z_HOME, which homes Z repeatedly

Matthew Lloyd 24 Dec 28, 2022
Margin Calculator - Personally tailored investment tool

Margin Calculator - Personally tailored investment tool

1 Jul 19, 2022
Social reading and reviewing, decentralized with ActivityPub

BookWyrm Social reading and reviewing, decentralized with ActivityPub Contents Joining BookWyrm Contributing About BookWyrm What it is and isn't The r

BookWyrm 1.4k Jan 08, 2023
Algorand Python API examples

Algorand-Py Algorand Python API examples This repo will hold example scripts to monitor activities on Algorand main net. You can: Monitor your assets

Karthik Dutt 2 Jan 23, 2022
Some out-of-the-box hooks for pre-commit

pre-commit-hooks Some out-of-the-box hooks for pre-commit. See also: https://github.com/pre-commit/pre-commit Using pre-commit-hooks with pre-commit A

pre-commit 3.6k Dec 29, 2022
💡 Fully automatic light management based on conditions like motion, illuminance, humidity, and other clever features

Fully automatic light management based on motion as AppDaemon app. 🕓 multiple daytimes to define different scenes for morning, noon, ... 💡 supports

Ben 105 Dec 23, 2022
Here, I have discuss the three methods of list reversion. The three methods are built-in method, slicing method and position changing method.

Three-different-method-for-list-reversion Here, I have discuss the three methods of list reversion. The three methods are built-in method, slicing met

Sachin Vinayak Dabhade 4 Sep 24, 2021
Never miss a deadline again

Hack the Opportunities Never miss a deadline again! Link to the excel sheet Contribution This list is not complete and I alone cannot make it whole. T

Vibali Joshi 391 Dec 28, 2022
A python package that computes an optimal motion plan for approaching a red light

redlight_approach redlight_approach is a Python package that computes an optimal motion plan during traffic light approach. RLA_demo.mov Given the par

Jonathan Roy 4 Oct 27, 2022
Adjust the white point, gamma or make your XDR display darker without losing HDR peak luminance or the ability to adjust display brightness

XDR Tuner Adjust the white point, gamma or make your XDR display darker without losing HDR peak luminance or the ability to adjust display brightness

François Simond 16 Dec 28, 2022