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
Distribute PySPI jobs across a PBS cluster

Distribute PySPI jobs across a PBS cluster This repository contains scripts for distributing PySPI jobs across a PBS-type cluster. Each job will conta

Oliver Cliff 1 Feb 10, 2022
Search and Find Jobs in Ethiopia

✨ EthioJobs ✨ Search and Find Jobs in Ethiopia Easy start critical warning Use pycharm No vscode No sublime No Vim No nothing when you want to use

Abdimk 12 Nov 09, 2022
An advanced NFT Generator

NFT Generator An advanced NFT Generator Free software: GNU General Public License v3 Documentation: https://nft-generator.readthedocs.io. Features TOD

NFT Generator 5 Apr 21, 2022
Python pyside2 kütüphanesi ile oluşturduğum drone için yer kontrol istasyonu yazılımı.

Ground Control Station (Yer Kontrol İstasyonu) Teknofest yarışmasında yerlilik kısmında Yer Kontrol İstasyonu yazılımı seçeneği bulunuyordu. Bu yüzden

Emirhan Bülbül 4 May 14, 2022
A visidata plugin for parsing f5 ltm/gtm/audit logs

F5 Log Visidata Plugin This plugin supports the default log format for: /var/log/ltm* /var/log/gtm* /var/log/apm* /var/log/audit* It extracts common l

James Deucker 1 Jan 06, 2022
A Kodi add-on for watching content hosted on PeerTube.

A Kodi add-on for watching content hosted on PeerTube. This add-on is under development so only basic features work, and you're welcome to improve it.

1 Dec 18, 2021
The dynamic code loading framework used in LocalStack

localstack-plugin-loader localstack-plugin-loader is the dynamic code loading framework used in LocalStack. Install pip install localstack-plugin-load

LocalStack 5 Oct 09, 2022
Python module to work with Magneto Database directly without using broken Magento 2 core

Python module to work with Magneto Database directly without using broken Magento 2 core

Egor Shitikov 13 Nov 10, 2022
Yandex Media Browser

Браузер медиа для плагина Yandex Station Включайте музыку, плейлисты и радио на Яндекс.Станции из Home Assistant! Скриншот Корневой раздел: Библиотека

Alexander Ryazanov 35 Dec 19, 2022
Data Science Course at Dept. of Computer Engineering, Chula 2022

2110446 Data Science Course at Chula 2022 Short links for exercises: Week1: Intro to Numpy, Pandas Numpy: https://colab.research.google.com/github/kao

Kao Panboonyuen 17 Nov 27, 2022
Password manager using MySQL and Python 3.10.2

Password Manager Password manager using MySQL and Python 3.10.2 Installation Install my-project with github git clone https://github.com/AyaanSiddiq

1 Feb 18, 2022
x-tools is a collection of tools developed in Python

x-tools X-tools is a collection of tools developed in Python Commands\

5 Jan 24, 2022
Sample microservices application demo

Development mode docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d or export COMPOSE_FILE='docker-compose.yml:docker-compose.dev.ym

Konstantinos Bairaktaris 1 Nov 14, 2021
scap is a tool for putting code in places and for other purposes

Scap is the deployment script used by Wikimedia Foundation to publish code and configuration on production web servers.

Wikimedia 7 Nov 02, 2022
Imports an object based on a string import_string('package.module:function_name')() - Based on werkzeug.utils

DEPRECATED don't use it. Please do: import importlib foopath = 'src.apis.foo.Foo' module_name = '.'.join(foopath.split('.')[:-1]) # to get src.apis.f

Bruno Rocha Archived Projects 11 Nov 12, 2022
Skip spotify ads by automatically restarting application when ad comes

SpotiByeAds No one likes interruptions! Don't you hate it when you're listening to your favorite jazz track or your EDM playlist and an ad for Old Spi

Partho 287 Dec 29, 2022
A data engineering project with Kafka, Spark Streaming, dbt, Docker, Airflow, Terraform, GCP and much more!

Streamify A data pipeline with Kafka, Spark Streaming, dbt, Docker, Airflow, Terraform, GCP and much more! Description Objective The project will stre

Ankur Chavda 206 Dec 30, 2022
A Python feed reader library.

reader is a Python feed reader library. It aims to allow writing feed reader applications without any business code, and without enforcing a dependenc

266 Dec 30, 2022
Python PID Controller and Process Simulator (FOPDT) with GUI.

PythonPID_Simulator Python PID Controller and Process Simulator (FOPDT) with GUI. Run the File. Then select Model Values and Tune PID.. Hit Refresh to

19 Oct 14, 2022
Build Xmas cards with user inputs

Automatically build Xmas cards with user inputs

Anand 9 Jan 25, 2022