Skip to main content

Neo4j Graph Data Science Client

Latest version PyPI downloads month Python versions Documentation Discord Community forum License

graphdatascience is a Python client for operating and working with the Neo4j Graph Data Science (GDS) library. It enables users to write pure Python code to project graphs, run algorithms, as well as define and use machine learning pipelines in GDS.

The API is designed to mimic the GDS Cypher procedure API in Python code. It abstracts the necessary operations of the Neo4j Python driver to offer a simpler surface. Additionally, the client-specific graph, model, and pipeline objects offer convenient functions that heavily reduce the need to use Cypher to access and operate these GDS resources.

graphdatascience is only guaranteed to work with GDS versions 2.0+.

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

Installation

To install the latest deployed version of graphdatascience, simply run:

pip install graphdatascience

Getting started

To use the GDS Python Client, we first need a gds object connected to a GDS deployment. How to get one depends on where GDS runs.

GDS Sessions (Aura Graph Analytics)

To run GDS via Aura Graph Analytics, use GdsSessions with an Aura API key pair and your AuraDB connection information:

from graphdatascience.session import AuraAPICredentials, DbmsConnectionInfo, GdsSessions, SessionMemory

sessions = GdsSessions(api_credentials=AuraAPICredentials("my-client-id", "my-client-secret"))

# Optional: estimate the session memory needed for your workload
memory = sessions.estimate(node_count=2_000, relationship_count=5_000, algorithms=["pageRank"])

gds = sessions.get_or_create(
    session_name="my-session",
    memory=memory,  # or a fixed size, e.g. SessionMemory.m_4GB
    db_connection=DbmsConnectionInfo(
        "neo4j+s://my-aura-db.databases.neo4j.io",
        "neo4j",
        "my-password",
    ),
)

# ... project graphs, run algorithms, train models, see the usage example below ...

# When you are done, tear down the session
gds.delete()
# or: sessions.delete(session_name="my-session")

Sessions can also run standalone, without an attached AuraDB, by passing a cloud_location instead of a db_connection. See the GDS Python Client Manual for details.

Self-managed Neo4j or GDS plugin

If you connect to a self-managed Neo4j database with the GDS plugin installed, instantiate a GraphDataScience object directly:

from graphdatascience import GraphDataScience

# When connecting to an AuraDS instance, the client automatically applies the AuraDS-recommended driver settings
gds = GraphDataScience("neo4j+s://my-aura-ds.databases.neo4j.io:7687", auth=("neo4j", "my-password"))

# Import the Cora dataset to GDS
G = gds.graph.datasets.load_cora()
assert G.node_count() == 2_708

# Run PageRank in mutate mode on G
pagerank_result = gds.page_rank.mutate(G, tolerance=0.5, mutate_property="pagerank")
assert pagerank_result["node_properties_written"] == G.node_count()

# Create a Node Classification pipeline
pipeline, _ = gds.pipeline.node_classification.create("my-pipe")

# Add a Degree Centrality feature to the pipeline
pipeline.add_node_property("degree", mutate_property="rank")
pipeline.select_features("rank")
details = pipeline.details()
assert details.feature_properties == [{"feature": "rank"}]

# Add a training method
pipeline.add_logistic_regression(penalty=(0.1, 2))

# Train a model on G
model, train_result = pipeline.train(
    G, model_name="my-model", target_property="subject", metrics=["ACCURACY"]
)
assert model.metrics()["ACCURACY"]["test"] > 0
assert train_result.train_millis >= 0

# Compute predictions in stream mode
predictions = model.predict_stream(G)
assert len(predictions) == G.node_count()

For additional examples and extensive documentation of all capabilities, please refer to the GDS Python Client Manual.

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

Documentation

The primary source for learning everything about the GDS Python Client is the manual, hosted at https://neo4j.com/docs/graph-data-science-client/current/. The manual is versioned to cover all GDS Python Client versions, so make sure to use the correct version to get the correct information.

Known limitations

Operations known to not yet work with graphdatascience:

License

graphdatascience is licensed under the Apache Software License version 2.0. All content is copyright © Neo4j Sweden AB.

Acknowledgements

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

Release files for graphdatascience 2.0

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

Source distribution (sdist)

Source distribution for graphdatascience 2.0
File Size Uploaded
graphdatascience-2.0.tar.gz 1.8 MB Details

Built distribution (wheel)

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

Total release size: 3.9 MB

Release files / graphdatascience-2.0.tar.gz

Download URL graphdatascience-2.0.tar.gz
Size 1.8 MB
Tags Source
SHA-256 checksum
How to use checksums
f583677a0fe1d10346381a45a6f06a259bf9ce7d82ff40d9c42c793e1b9045aa
BLAKE2b-256 checksum
How to use checksums
f33e04ec09f9bbe62ae04e295e6a59d06acc2a55cba13e355a7db8e026f65667
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / graphdatascience-2.0-py3-none-any.whl

Download URL graphdatascience-2.0-py3-none-any.whl
Size 2.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
5c19253cb04776e65e48ed88837c113f047bdf2416f6377d68de5b65ae445dec
BLAKE2b-256 checksum
How to use checksums
4eb4904997df96df66c85f371cca7d129bfa71ded6cfc9f10de4e3c37eedb57b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

2.0 This release

2 release files

1.22

2 release files

1.21

2 release files

1.20

2 release files

1.19

2 release files

1.18

2 release files

1.17

2 release files

1.16

2 release files

1.15.1

2 release files

1.15

2 release files

1.14

2 release files

1.13

2 release files

1.12

2 release files

1.11

2 release files

1.10

2 release files

1.9

2 release files

1.8

2 release files

1.7

2 release files

1.6

2 release files

1.5

2 release files

1.4

2 release files

1.3

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

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