GraphDataScience¶
- class graphdatascience.GraphDataScience¶
Primary API class for the Neo4j Graph Data Science Python Client. Always bind this object to a variable called gds.
- __init__(endpoint: str | Driver | QueryRunner, auth: tuple[str, str] | None = None, aura_ds: bool = False, database: str | None = None, arrow: str | bool = True, arrow_disable_server_verification: bool = True, arrow_tls_root_certs: bytes | None = None, bookmarks: Any | None = None, show_progress: bool = True, arrow_client_options: dict[str, Any] | None = None)¶
Construct a new GraphDataScience object.
- Parameters:
endpoint (str | Driver | QueryRunner) – The Neo4j endpoint to connect to. Most commonly, this is a Bolt connection URI.
auth (tuple[str, str] | None, default None) – A username, password pair for database authentication.
aura_ds (bool, default False) – A flag that indicates that that the client is used to connect to a Neo4j AuraDS instance.
database (str | None, default None) – The Neo4j database to query against.
arrow (str | bool, default True) –
Arrow connection information. This is either a string or a bool.
If it is a string, it will be interpreted as a connection URL to a GDS Arrow Server.
- If it is a bool:
True will make the client discover the connection URI to the GDS Arrow server via the Neo4j endpoint.
False will make the client use Bolt for all operations.
arrow_disable_server_verification (bool, default True) –
Deprecated since version 1.16: Use arrow_client_options instead
A flag that overrides other TLS settings and disables server verification for TLS connections.
arrow_tls_root_certs (bytes | None, default None) –
Deprecated since version 1.16: Use arrow_client_options instead
PEM-encoded certificates that are used for the connection to the GDS Arrow Flight server.
bookmarks (Any | None, default None) – The Neo4j bookmarks to require a certain state before the next query gets executed.
show_progress (bool, default True) – A flag to indicate whether to show progress bars for running procedures.
arrow_client_options (dict[str, Any] | None, default None) – Additional options to be passed to the Arrow Flight client.
- bookmarks() Any | None¶
Get the Neo4j bookmarks defining the currently required states for queries to execute
- Return type:
The (possibly None) Neo4j bookmarks defining the currently required state
- close() None¶
Close the GraphDataScience object and release any resources held by it.
If the GraphDataScience object was instantiated with a Neo4j Driver, the driver will not be closed as we cannot assume sole ownership of it.
- Return type:
None
- database() str | None¶
Get the database which queries are run against.
- Returns:
The name of the database.
- Return type:
str | None
- driver_config() dict[str, Any]¶
Get the configuration used to create the underlying driver used to make queries to Neo4j.
- find_node_id(labels: list[str] = [], properties: dict[str, Any] = {}) int¶
Find the node id of a node with the given labels and properties.
- classmethod from_neo4j_driver(driver: Driver, auth: tuple[str, str] | None = None, database: str | None = None, arrow: str | bool = True, arrow_disable_server_verification: bool = True, arrow_tls_root_certs: bytes | None = None, bookmarks: Any | None = None, arrow_client_options: dict[str, Any] | None = None) GraphDataScience¶
Construct a new GraphDataScience object from an existing Neo4j Driver. This method is useful when you already have a Neo4j Driver instance and want to use it with the GDS client.
- Parameters:
driver (Driver) – The Neo4j Driver instance to use.
auth (tuple[str, str] | None, default None) – A username, password pair for authentication.
database (str | None, default None) – The Neo4j database to query against.
arrow (str | bool, default True) –
Arrow connection information. This is either a string or a bool.
If it is a string, it will be interpreted as a connection URL to a GDS Arrow Server.
- If it is a bool:
True will make the client discover the connection URI to the GDS Arrow server via the Neo4j endpoint.
False will make the client use Bolt for all operations.
arrow_disable_server_verification (bool, default True) –
Deprecated since version 1.16: Use arrow_client_options instead
A flag that overrides other TLS settings and disables server verification for TLS connections.
arrow_tls_root_certs (bytes | None, default None) –
Deprecated since version 1.16: Use arrow_client_options instead
PEM-encoded certificates that are used for the connection to the GDS Arrow Flight server.
bookmarks (Any | None, default None) – The Neo4j bookmarks to require a certain state before the next query gets executed.
show_progress (bool, default True) – A flag to indicate whether to show progress bars for running procedures.
arrow_client_options (dict[str, Any] | None, default None) – Additional options to be passed to the Arrow Flight client.
Returns – A new GraphDataScience object. configured with the provided Neo4j Driver.
- Return type:
- last_bookmarks() Any | None¶
Get the Neo4j bookmarks defining the state following the most recently called query
- Return type:
The (possibly None) Neo4j bookmarks defining the state following the most recently called query
- list() DataFrame¶
List all available GDS procedures.
- Returns:
A DataFrame containing all available GDS procedures.
- Return type:
DataFrame
- lp_pipe(name: str) LPTrainingPipeline¶
Create a Link Prediction training pipeline, with all default settings.
- Parameters:
name (str) – The name to give the pipeline. Must be unique within the Pipeline Catalog.
- Returns:
A new instance of a Link Prediction pipeline object.
- Return type:
- nc_pipe(name: str) NCTrainingPipeline¶
Create a Node Classification training pipeline, with all default settings.
- Parameters:
name (str) – The name to give the pipeline. Must be unique within the Pipeline Catalog.
- Returns:
A new instance of a Node Classification pipeline object.
- Return type:
- nr_pipe(name: str) NRTrainingPipeline¶
Create a Node Regression training pipeline, with all default settings.
- Parameters:
name (str) – The name to give the pipeline. Must be unique within the Pipeline Catalog.
- Returns:
A new instance of a Node Regression pipeline object.
- Return type:
- run_cypher(query: str, params: dict[str, Any] | None = None, database: str | None = None, retryable: bool = False, mode: QueryMode = QueryMode.WRITE) DataFrame¶
Run a Cypher query
- Parameters:
query (str) – the Cypher query
database (str) – the database on which to run the query
retryable (bool) – whether the query can be automatically retried. Make sure the query is idempotent if set to True.
mode (QueryMode) – the query mode to use (READ or WRITE). Set based on the operation performed in the query.
Returns – The query result as a DataFrame
- Return type:
DataFrame
- server_version() ServerVersion¶
Get the version of the GDS library.
- Returns:
The version of the GDS library.
- Return type:
- set_bookmarks(bookmarks: Any) None¶
Set Neo4j bookmarks to require a certain state before the next query gets executed
- Parameters:
bookmarks (Bookmark(s)) – The Neo4j bookmarks defining the required state
- Return type:
None
- set_database(database: str) None¶
Set the database which queries are run against.
- Parameters:
database (str) – The name of the database to run queries against.
- Return type:
None
- set_show_progress(show_progress: bool) None¶
Set whether to show progress for running procedures.
- Parameters:
show_progress (bool) – Whether to show progress for procedures.
- Return type:
None
- property v2: PluginV2Endpoints¶
Return preview v2 endpoints. These endpoints may change without warning. These endpoints are a preview of the API for the next major version of this library.