arcgis.graph module

The arcgis.graph module contains classes and functions for working with ArcGIS Knowledge graphs. The available functions allow for searching and querying the graph data, and viewing the data model of the graph database.

Knowledge graphs consist of entities and the relationships between them, each of which can contain properties which describe their attributes. The data model of the knowledge graph can show you which entities, relationships, and properties are in your database, along with other information about the graph. Performing a search or openCypher query on the graph will return results from the database based on the search or query terms provided.

Note

Applications based on ArcGIS API for Python version 2.0.1 can only communicate with knowledge graphs in an ArcGIS Enterprise 10.9.1 or 11.0 deployment. ArcGIS Enterprise 11.1 includes breaking changes for knowledge graphs. Only applications based on ArcGIS API for Python version 2.1.0 or later will be able to communicate with knowledge graphs in an Enterprise 11.1 deployment. See the ArcGIS Enterprise Knowledge Server documentation for more details.

KnowledgeGraph

class arcgis.graph.KnowledgeGraph(url, *, gis=None)

Provides access to the Knowledge Graph service data model and properties, as well as methods to search and query the graph.

Parameter

Description

url

Knowledge Graph service URL

gis

an authenticated arcigs.gis.GIS object.

# Connect to a Knowledge Graph service:

gis = GIS(url="url",username="username",password="password")

knowledge_graph = KnowledgeGraph(url, gis=gis)
property datamodel

Returns the datamodel for the Knowledge Graph service

classmethod fromitem(item)

Returns the Knowledge Graph service from an Item

property properties

Returns the properties of the Knowledge Graph service

query(query)

Queries the Knowledge Graph using openCypher

Learn more about querying a knowledge graph

Parameter

Description

query

Required String. Allows you to return the entities and relationships in a graph, as well as the properties of those entities and relationships, by providing an openCypher query.

# Perform an openCypher query on the knowledge graph
query_result = knowledge_graph.query("MATCH path = (n)-[r]-(n2) RETURN path LIMIT 5")
Returns

List[list]

search(search, category='both')

Allows for the searching of the properties of entities, relationships, or both in the graph using a full-text index.

Learn more about searching a knowledge graph

Parameter

Description

search

Required String. The search to perform on the Knowledge Graph.

category

Optional String. The category is the location of the full text search. This can be isolated to either the entities or the relationships. The default is to look in both.

The allowed values are: both, entities, relationships

Note

Check the service definition for the Knowledge Graph service for valid values of category. Not all services support both.

#Perform a search on the knowledge graph
search_result = knowledge_graph.search("cat")

# Perform a search on only entities in the knowledge graph
searchentities_result = knowledge_graph.search("cat", "entities")
Returns

List[list]

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.