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: str, *, 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
GIS
object.# Connect to a Knowledge Graph service: gis = GIS(url="url",username="username",password="password") knowledge_graph = KnowledgeGraph(url, gis=gis)
- apply_edits(adds: Sequence[dict[str, Any] | Entity | Relationship] = [], updates: Sequence[dict[str, Any] | Entity | Relationship] = [], deletes: Sequence[dict[str, Any] | EntityDelete | RelationshipDelete] = [], input_transform: dict[str, Any] | Transform | None = None, cascade_delete: bool = False, cascade_delete_provenance: bool = False, as_dict: bool = True) dict | ApplyEditsResponse
Allows users to add, update, and delete
Entity
andRelationship
.Note
objectid values are not supported in dictionaries for apply_edits
Parameter
Description
adds
Optional list of
Entity
orRelationship
. The list of objects to add to the graph, represented in dictionary format.updates
Optional list of
Entity
orRelationship
. The list of existent graph objects that are to be updated, represented in dictionary format.deletes
Optional list of
EntityDelete
orRelationshipDelete
. The list of existent objects to remove from the graph, represented in dictionary format.input_transform
Optional
Transform
. Allows a user to specify custom quantization parameters for input geometry, which dictate how geometries are compressed and transferred to the server. Defaults to lossless WGS84 quantization.cascade_delete
Optional boolean. When True, relationships connected to entities that are being deleted will automatically be deleted as well. When False, these relationships must be deleted manually first. Defaults to False.
cascade_delete_provenance
Optional boolean. When True, deleting entities/relationships or setting their property values to null will result in automatic deletion of associated provenance records. When False, apply_edits() will fail if there are provenance records connected to entities/relationships intended for deletion or having their properties set to null.
as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
from arcgis.graph import Entity, Relationship add_entity = Entity(type_name="Company", properties={"name": "Esri"}) delete_relationship = DeleteRelationship(type_name="WorksAt", ids=[UUID("783bd422-3hfp-45c7-87aa-8adbbdac0a3d")]) graph.apply_edits(adds=[add_entity], deletes=[delete_relationship], as_dict=False)
- Returns:
- constraint_rule_adds(rules: Sequence[dict[str, Any] | ConstraintRule], as_dict: bool = True) dict | ConstraintRuleAddsResponse
Adds constraint rules for entities & relationships to the data model.
RelationshipExclusionRule
is a constraint rule.Parameter
Description
rules
Required Sequence of
RelationshipExclusionRule
. Defines the constraint rules to be added.as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
from arcgis.graph import RelationshipExclusionRule graph.constraint_rule_adds( rules=[ RelationshipExclusionRule( name="OnlyPersonCanWorkAtCompany", origin_entity_types=SetOfNamedTypes(set_complement=["Person"]), relationship_types=SetOfNamedTypes(set=["WorksAt"]), destination_entity_types=SetOfNamedTypes(set=["Company"]) ) ], as_dict=False )
- Returns:
- constraint_rule_deletes(rule_names: Sequence[str], as_dict: bool = True) dict | ConstraintRuleDeletesResponse
Deletes existing constraint rules for entities & relationships from the data model.
RelationshipExclusionRule
is a constraint rule.Parameter
Description
rule_names
Required Sequence of strings. The names of the constraint rules to be deleted, as defined in a rule’s ‘name’ attribute.
as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
# Delete a constraint rule from the Knowledge Graph's data model. graph.constraint_rule_deletes(["constraint_rule_1"], as_dict=False)
- Returns:
- constraint_rule_updates(rules: Sequence[dict[str, Any] | ConstraintRuleUpdate], as_dict: bool = True) dict | ConstraintRuleUpdatesResponse
Update
ConstraintRule
for entities & relationships in the data model.RelationshipExclusionRule
is a type of constraint rule.Parameter
Description
rules
Required Sequence of
RelationshipExclusionRuleUpdate
. Defines the constraint rules to be updated.as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
from arcgis.graph import RelationshipExclusionRuleUpdate, ConstraintRule, ConstraintRuleMask, UpdateSetOfNamedTypes graph.constraint_rule_updates( rules=[ RelationshipExclusionRuleUpdate( rule_name="OnlyPersonCanWorkForCompany", mask=ConstraintRuleMask(update_name=True, update_alias=True), constraint_rule=ConstraintRule( name="PersonCanWorkForCompanyOrPark", alias="Person Can Work For Company or Park" ) ) ], as_dict=False )
- Returns:
- graph_property_adds(type_name: str, graph_properties: Sequence[dict[str, Any] | GraphProperty], as_dict: bool = True) dict | PropertyAddsResponse
Adds set of
GraphProperty
to a named type in the data modelLearn more about adding properties in a knowledge graph
Parameter
Description
type_name
Required string. The entity or relationship type to which the properties will be added.
graph_properties
Required Sequence of
GraphProperty
. The Sequence of properties to add to the named type.as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
from arcgis.graph import GraphProperty graph.graph_property_adds(type_name="Vehicle", graph_properties=[GraphProperty(name="year")])
- Returns:
- graph_property_delete(type_name: str, property_name: str, as_dict: bool = True) dict | PropertyDeleteResponse
Delete a
GraphProperty
for a named type in the data modelLearn more about deleting properties in a knowledge graph
Parameter
Description
type_name
Required string. The entity or relationship type containing the property to be deleted.
property_name
Required string. The property to be deleted.
as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
# Delete a named type's property in the data model delete_result = knowledge_graph.graph_property_delete("Person", "Address", as_dict=False)
- Returns:
- graph_property_index_adds(type_name: str, field_indexes: Sequence[dict[str, Any] | FieldIndex], as_dict: bool = True) dict | IndexAddsResponse
Adds one or more
FieldIndex
to a field or multiple fields associated with a named type in the data model.Learn more about adding graph property indexes in a knowledge graph
Parameter
Description
type_name
Required string. The entity or relationship type to add the indexes to.
field_indexes
Required list of dicts. The indexes to add for the type. See below for an example of the structure.
as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
from arcgis.graph import FieldIndex graph.graph_property_index_adds( type_name="Person", field_indexes=[FieldIndex(name="name_index", is_ascending=True, is_unique=False, fields=["name"])], as_dict=False )
- Returns:
- graph_property_index_deletes(type_name: str, field_indexes: Sequence[str], as_dict: bool = True) dict | IndexDeletesResponse
Deletes one or more
FieldIndex
from fields associated with a named type in the data model.Learn more about deleting graph property indexes from a knowledge graph
Parameter
Description
type_name
Required string. The entity or relationship type to delete the field indexes from.
field_indexes
Required Sequence of strings. The field indexes to delete from the type.
as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
# Delete field indexes from a Knowledge Graph type delete_result = graph.graph_property_index_deletes("Project", ["title"], as_dict=False)
- Returns:
- graph_property_update(type_name: str, property_name: str, graph_property: dict[str, Any] | GraphProperty, mask: dict[str, Any] | GraphPropertyMask, as_dict: bool = True) dict | PropertyUpdateResponse
Updates a
GraphProperty
for a named type in the data modelLearn more about updating properties in a knowledge graph
Parameter
Description
type_name
Required string. The entity or relationship type containing the property to be updated.
property_name
Required string. The property to be updated.
graph_property
Required
GraphProperty
. The graph property to be updated.mask
Required
GraphPropertyMask
. The properties of the field to be updated.as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
from arcgis.graph import GraphProperty, GraphPropertyMask graph.graph_property_update( type_name="Vehicle", property_name="year", graph_property=GraphProperty(name="year", alias="year_made"), mask=GraphPropertyMask(update_alias=True), as_dict=False )
- Returns:
- named_object_type_adds(entity_types: Sequence[dict[str, Any] | EntityType] = [], relationship_types: Sequence[dict[str, Any] | RelationshipType] = [], as_dict: bool = True) dict | NamedObjectTypeAddsResponse
Adds
EntityType
andRelationshipType
to the data modelLearn more about adding named types to a knowledge graph
Parameter
Description
entity_types
Optional list of EntityTypes. The list of entity types to add to the data model, represented in dictionary format.
relationship_types
Optional list of RelationshipTypes. The list of relationship types to add to the data model, represented in dictionary format.
as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
from arcgis.graph import EntityType, RelationshipType, GraphProperty entity_type_add = EntityType(name="Vehicle", properties={"make": GraphProperty(name="make")}) relationship_type_add = RelationshipType(name="Drives") graph.named_object_type_adds(entity_types=[entity_type_add], relationship_types=[relationship_type_add], as_dict=False)
- Returns:
- named_object_type_delete(type_name: str, as_dict: bool = True) dict | NamedObjectTypeDeleteResponse
Deletes an
EntityType
orRelationshipType
in the data modelLearn more about deleting named types in a knowledge graph
Parameter
Description
type_name
Required string. The named type to be deleted.
as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
# Delete a named type in the data model delete_result = graph.named_object_type_delete("Person")
- Returns:
- named_object_type_update(type_name: str, named_type_update: dict[str, Any] | EntityType | RelationshipType, mask: dict[str, Any] | NamedObjectTypeMask, as_dict: bool = True) dict | NamedObjectTypeUpdateResponse
Updates an
EntityType
orRelationshipType
in the data modelLearn more about updating named types in a knowledge graph
Parameter
Description
type_name
Required string. The named type to be updated.
named_type_update
Required Union[
EntityType
,RelationshipType
]. The entity or relationship type to be updated.mask
Required
NamedObjectTypeMask
. The properties of the named type to be updated.as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
from arcgis.graph import EntityType, NamedObjectTypeMask type_update = EntityType(name="Vehicle", alias="Car") graph.named_object_type_update( type_name="Vehicle", named_type_update=type_update, mask=NamedObjectTypeMask(update_alias=True), as_dict=False )
- Returns:
- query(query: str) List[dict]
Deprecated since version 2.4.1: Removed in: 3.0.0. Use query_streaming instead.
Deprecated since version 2.4.1: Removed in: 3.0.0. Use query_streaming instead.
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]
- query_data_model(as_dict: bool = True) dict | GraphDataModel
Returns the datamodel for the Knowledge Graph service
Parameter
Description
as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
# Query knowledge graph data model knowledge_graph.query_data_model(as_dict=False)
- Returns:
- query_streaming(query: str, input_transform: dict[str, Any] | Transform | None = None, bind_param: dict[str, Any] = {}, include_provenance: bool = False, as_dict: bool = True) Generator[Sequence[Any], None, None]
Query the graph using an openCypher query. Allows for more customization than the base
query()
function. Creates a generator of the query results, from which users can access each row or add them to a list. See below for example usage.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.
input_transform
Optional dict or Transform. Allows a user to specify custom quantization parameters for input geometry, which dictate how geometries are compressed and transferred to the server. Defaults to lossless WGS84 quantization.
bind_param
Optional dict. The bind parameters used to filter query results. Key of each pair is the string name for it, which is how the parameter can be referenced in the query. The value can be any “primitive” type value that may be found as an attribute of an entity or relationship (e.g., string, double, boolean, etc.), a list, an anonymous object (a dict), or a geometry.
Anonymous objects and geometries can be passed in as either their normal Python forms, or following the format found in Knowledge Graph entries (containing an “_objectType” key, and “_properties” for anonymous objects).
Note: Including bind parameters not used in the query will cause queries to yield nothing on ArangoDB based services, while Neo4j based services will still produce results.
include_provenance
Optional boolean. When True, provenance entities (metadata) will be included in the query results. Defaults to False.
# Get a list of all query results query_gen = knowledge_graph.query_streaming("MATCH path = (n)-[r]-(n2) RETURN path LIMIT 5") results = list(gen) # Grab one result at a time query_gen = knowledge_graph.query_streaming("MATCH path = (n)-[r]-(n2) RETURN path LIMIT 5") first_result = next(query_gen) second_result = next(query_gen)
- Returns:
Generator[Sequence[Any], None, None]
- search(search: str, category: str = 'both', as_dict: bool = True) List[Sequence[Any]]
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, both_entity_relationship, and meta_entity_provenance. Both and both_entity_relationship are functionally the same.
as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
Note
Check the service definition for the Knowledge Graph service for valid values of category. Not all services support both and both_entity_relationship.
#Perform a search on the knowledge graph for search_result in knowledge_graph.search("cat", as_dict=False): print(search_result) # Perform a search on only entities in the knowledge graph for searchentities_result in knowledge_graph.search("cat", "entities", as_dict=False): print(searchentities_result)
- Returns:
Generator[Sequence[Any], None, None]
- sync_data_model(as_dict: bool = True) dict | SyncDataModelResponse
Synchronizes the Knowledge Graph Service’s data model with any changes made in the database. Will return any errors or warnings from the sync.
Parameter
Description
as_dict
Optional Boolean. Determines whether the result is returned as a dictionary or an object. The default is True. False is recommended.
# Synchronize the data model sync_result = knowledge_graph.sync_data_model(as_dict=False)
- Returns:
- update_search_index(adds: dict[str, dict | SearchIndexProperties] = {}, deletes: dict[str, dict | SearchIndexProperties] = {}, as_dict: bool = True) dict | UpdateSearchIndexResponse
Allows users to add or delete
SearchIndexProperties
for differentEntityType
andRelationshipType
from theGraphDataModel
. Can only be existent properties for a given entity/relationship type.from arcgis.graph import SearchIndexProperties graph.update_search_index( adds={"Person": SearchIndexProperties(property_names=["name"])}, as_dict=False )
- Returns:
Data Model Types
ConstraintRule
- pydantic model arcgis.graph.data_model_types.ConstraintRule
Represents an constraint rule to define how data can be created in the knowledge graph.
Parameter
Description
name
Required String. Name for the exclusion rule.
alias
Optional String. The default value is “”.
disabled
Optional Boolean. The default value is False.
role
Optional esriGraphConstraintRuleRole. The default value is “esriGraphConstraintRuleRoleRegular”..
from arcgis.graph import ConstraintRule # Example 1: Update a constraint rule person_company_constraint = ConstraintRule(name="PersonCanWorkForCompanyOrPark", alias="Person Can Work For Company or Park") graph.constraint_rule_updates( rules=[ RelationshipExclusionRuleUpdate( rule_name="OnlyPersonCanWorkForCompany", mask=ConstraintRuleMask(update_name=True, update_alias=True), constraint_rule=person_company_constraint ) ], as_dict=False ) # Example 2: Access an exclusion rule from the data model data_model = graph.query_data_model() data_model.constraint_rules
- field role: Literal['esriGraphConstraintRuleRoleUNSPECIFIED', 'esriGraphConstraintRuleRoleRegular', 'esriGraphConstraintRuleRoleHasDocument', 'esriGraphConstraintRuleRoleNoProvenanceOrigin', 'esriGraphConstraintRuleRoleNoProvenanceDestination'] = 'esriGraphConstraintRuleRoleRegular'
The constraint rule role.
ConstraintRuleMask
- pydantic model arcgis.graph.data_model_types.ConstraintRuleMask
Allows users to define which settings to update for a contraint rule
Parameter
Description
update_name
Optional Boolean. The default value is False.
update_alias
Optional Boolean. The default value is False.
update_disabled
Optional Boolean. The default value is False.
from arcgis.graph import ConstraintRuleMask ConstraintRuleMask(update_name=True, update_alias=True, update_disabled=True)
EndPoint
- pydantic model arcgis.graph.data_model_types.EndPoint
Represents a set of origin and destination entity types for a relationship type
Parameter
Description
origin_enity_type
Required String. Name of origin entity type.
destination_entity_type
Required String. Name of destination entity type.
from arcgis.graph import EndPoint EndPoint("Person", "Company")
EntityType
- pydantic model arcgis.graph.data_model_types.EntityType
Represents an entity named object type for a Knowledge Graph.
Parameter
Description
name
Required String. Name for the Entity Type.
alias
Optional String. The default value is “”.
role
Optional esriGraphNamedObjectRole String. The default value is “esriGraphNamedObjectRegular”.
strict
Optional Boolean. The default value is False.
properties
Optional Dict(String,
GraphProperty
). The default value is {}.field_indexes
Optional Dict(String,
FieldIndex
). The default value is {}.from arcgis.graph import EntityType # Example 1: Define an entity type EntityType( name="Person", properties={"name": GraphProperty(name="name")}, field_indexes={"name_index": FieldIndex(name="name_index", is_ascending=True, is_unique=False, fields=["name"])} ) # Example 2: Access information about an entity type from the data model data_model = graph.query_data_model() data_model.entity_types['Person'].properties
FieldIndex
- pydantic model arcgis.graph.data_model_types.FieldIndex
Represents a field index to be used in
graph_property_index_adds()
.Parameter
Description
name
Required String. Name for the field index.
is_ascending
Required Boolean.
is_unique
Required Boolean.
fields
Required List(String). List of field names for the index.
from arcgis.graph import FieldIndex # Example 1: create a FieldIndex to use FieldIndex(name="name_index", is_ascending=True, is_unique=False, fields=["name"]) # Example 2: access FieldIndex in the data model data_model = graph.query_data_model() data_model.entity_types["Person"].field_indexes['name_index'].fields
GraphDataModel
- pydantic model arcgis.graph.data_model_types.GraphDataModel
Allows users to access information about the knowledge graph’s data model.
from arcgis.gis import GIS from arcgis.graph import KnowledgeGraph, GraphDataModel graph = KnowledgeGraph("URL to Knowledge Graph Service", gis=GIS("home")) data_model = graph.query_data_model() # Access the timestamp the data model was last update. The response will be an integer timestamp. data_model.data_model_timestamp # Access the spatial reference. The response will be a dictionary containing the spatial reference information. data_model.spatial_reference # Access entity types. The response will be a dictionary of string names and EntityType objects. data_model.entity_types # Access relationship types. The response will be a dictionary of string names and RelationshipType objects. data_model.relationship_types # Access meta entity types (example: Provenance). The response will be a dictionary of string names and EntityType objects. data_model.meta_entity_types # Access the boolean value of whether the data model is strict data_model.strict # Access the object id property name. The response will be a string. data_model.objectid_property # Access the global id property name. The response will be a string. data_model.globalid_property # Access the boolean value of whether the knowledge graph is ArcGIS managed. data_model.arcgis_managed # Access the identifier info. The response will be a IdentifierInfo object. data_model.identifier_info # Access the search indexes. The response will be a list of SearchIndex objects. data_model.search_indexes # Access the provenance source type values data_model.provenance_source_type_values # Access the constraint rules data_model.constraint_rules
- field constraint_rules: list[Annotated[ConstraintRule | RelationshipExclusionRule, Discriminator(discriminator=type, custom_error_type=None, custom_error_message=None, custom_error_context=None)]] = []
The list of constraint rules.
- field entity_types: list[EntityType] = []
The list of entity types in the data model.
- field meta_entity_types: list[EntityType] = []
The list of meta entity types in the data model.
- field provenance_source_type_values: ProvenanceSourceTypeValues = ProvenanceSourceTypeValues(value_behavior_array=[])
The Provenance source type values.
- field relationship_types: list[RelationshipType] = []
The list of relationship types in the data model.
- field search_indexes: list[SearchIndex] = []
The list of search indexes.
GraphProperty
- pydantic model arcgis.graph.data_model_types.GraphProperty
Represents a property of an
EntityType
orRelationshipType
in the Knowledge Graph.Parameter
Description
name
Required String. Name for the property. The default value is “”.
alias
Optional String. Alias for the property. The default value is “”.
domain
Optional String. Name of domain for the property. The default value is “”.
field_type
Optional esriFieldType string. The default value is “esriFieldTypeString”.
geometry_type
Optional esriGeometryType string. The default is None.
has_z
Optional Boolean. The default value is False.
has_m
Optional Boolean. The default value is False.
default_value
Optional Any value. The default value is None.
nullable
Optional Boolean. The default value is True.
visible
Optional Boolean. The default value is True.
editable
Optional Boolean. The default value is True.
required
Optional Boolean. The default value is False.
role
Optional esriGraphPropertyRole string. The default value is “esriGraphPropertyRegular”.
from arcgis.graph import GraphProperty # Example 1: simple string property GraphProperty(name="name", alias="name", required=True) # Example 2: geometry property GraphProperty(name="shape", field_type="esriFieldTypeGeoemtry", geometry_type="esriGeometryPolygon") # Example 3: get GraphProperty information from data model data_model = graph.query_data_model() data_model.entity_types['Person'].properties['name'].required # accesses the required property on the GraphProperty 'name'.
- field field_type: Literal['esriFieldTypeSmallInteger', 'esriFieldTypeInteger', 'esriFieldTypeSingle', 'esriFieldTypeDouble', 'esriFieldTypeString', 'esriFieldTypeDate', 'esriFieldTypeDateOnly', 'esriFieldTypeTimeOnly', 'esriFieldTypeTimestampOffset', 'esriFieldTypeOID', 'esriFieldTypeGeometry', 'esriFieldTypeBlob', 'esriFieldTypeRaster', 'esriFieldTypeGUID', 'esriFieldTypeGlobalID', 'esriFieldTypeXML', 'esriFieldTypeBigInteger'] = 'esriFieldTypeString'
The type of the property.
- field geometry_type: Literal['esriGeometryPoint', 'esriGeometryMultipoint', 'esriGeometryPolyline', 'esriGeometryPolygon', 'esriGeometryEnvelope'] | None = None
The geometry type, or None if not a geometry property.
- field role: Literal['esriGraphPropertyUNSPECIFIED', 'esriGraphPropertyRegular', 'esriGraphPropertyDocumentName', 'esriGraphPropertyDocumentTitle', 'esriGraphPropertyDocumentUrl', 'esriGraphPropertyDocumentText', 'esriGraphPropertyDocumentKeywords', 'esriGraphPropertyDocumentContentType', 'esriGraphPropertyDocumentMetadata', 'esriGraphPropertyDocumentFileExtension', 'esriGraphPropertyProvenanceInstanceId', 'esriGraphPropertyProvenanceSourceType', 'esriGraphPropertyProvenanceSourceName', 'esriGraphPropertyProvenanceSource', 'esriGraphPropertyProvenanceComment', 'esriGraphPropertyProvenanceTypeName', 'esriGraphPropertyProvenancePropertyName'] = 'esriGraphPropertyRegular'
The role of the property.
GraphPropertyMask
- pydantic model arcgis.graph.data_model_types.GraphPropertyMask
Allows users to define which settings should be updated for a
GraphProperty
during agraph_property_update()
.Parameter
Description
update_name
Optional Boolean. The default value is False.
update_alias
Optional Boolean. The default value is False.
update_domain
Optional Boolean. The default value is False.
update_field_type
Optional Boolean. The default value is False.
update_geometry_type
Optional Boolean. The default value is False.
update_has_z
Optional Boolean. The default value is False.
update_has_m
Optional Boolean. The default value is False.
update_default_value
Optional Boolean. The default value is False.
update_nullable
Optional Boolean. The default value is False.
update_visible
Optional Boolean. The default value is False.
update_editable
Optional Boolean. The default value is False.
update_required
Optional Boolean. The default value is False.
from arcgis.graph import GraphPropertyMask GraphPropertyMask(update_name=True, update_visible=True, update_editable=True)
NamedObjectTypeMask
- pydantic model arcgis.graph.data_model_types.NamedObjectTypeMask
Allows user to define what should be updated when performing a
named_object_type_update()
.Parameter
Description
update_name
Optional Boolean. The default value is False.
update_alias
Optional Boolean. The default value is False.
update_role
Optional Boolean. The default value is False.
update_strict
Optional Boolean. The default value is False.
from arcgis.graph import NamedObjectTypeMask NamedObjectTypeMask(update_name=True, update_alias=True, update_strict=True)
RelationshipExclusionRule
- pydantic model arcgis.graph.data_model_types.RelationshipExclusionRule
Represents an exclusion rule to define how relationships can be created in the knowledge graph between defined entity types.
Parameter
Description
name
Required String. Name for the exclusion rule.
alias
Optional String. The default value is “”.
disabled
Optional Boolean. The default value is False.
role
Optional esriGraphConstraintRuleRole. The default value is “esriGraphConstraintRuleRoleRegular”.
origin_entity_types
Required
SetOfNamedTypes
.relationship_types
Required
SetOfNamedTypes
.destination_entity_types
Required
SetOfNamedTypes
.from arcgis.graph import RelationshipExclusionRule, SetOfNamedTypes # Example 1: Define an exclusion rule RelationshipExclusionRule( name="OnlyPersonCanWorkAtCompany", origin_entity_types=SetOfNamedTypes(set_complement=["Person"]), relationship_types=SetOfNamedTypes(set=["WorksAt"]), destination_entity_types=SetOfNamedTypes(set=["Company"]) ) # Example 2: Access an exclusion rule from the data model data_model = graph.query_data_model() data_model.constraint_rules
- field destination_entity_types: SetOfNamedTypes [Required]
The destination entity types in the rule.
- field origin_entity_types: SetOfNamedTypes [Required]
The origin entity types in the rule.
- field relationship_types: SetOfNamedTypes [Required]
The relationship types in the rule.
RelationshipExclusionRuleUpdate
- pydantic model arcgis.graph.data_model_types.RelationshipExclusionRuleUpdate
Allows a user to provide information for updating a relationship exclusion rule
Parameter
Description
rule_name
Required String. Name of the constraint rule to update
mask
Required
ConstraintRuleMask
.constraint_rule
Required
RelationshipExclusionRule
.update_origin_entity_types
Required
UpdateSetOfNamedTypes
.update_relationship_types
Required
UpdateSetOfNamedTypes
.update_destination_entity_types
Required
UpdateSetOfNamedTypes
.from arcgis.graph import RelationshipExclusionRuleUpdate, RelationshipExclusionRule, ConstraintRuleMask RelationshipExclusionRuleUpdate( rule_name="OnlyPersonCanWorkForCompany", mask=ConstraintRuleMask(update_name=True, update_alias=True), constraint_rule=RelationshipExclusionRule( name="PersonCanOnlyWorkAtCompany", alais="Person Works At Company", origin_entity_types=SetOfNamedTypes(set_complement=["Person"]), relationship_types=SetOfNamedTypes(set=["WorksAt"]), destination_entity_types=SetOfNamedTypes(set=["Company"]) ), update_origin_entity_types=UpdateSetOfNamedTypes(add_named_types=["Employee"],remove_named_types=[]), update_relationship_types=UpdateSetOfNamedTypes(add_named_types=["WorksFor"],remove_named_types=["WorksAt"]), update_destination_entity_types=UpdateSetOfNamedTypes(add_named_types=["Park"],remove_named_types=[]) )
- field update_destination_entity_types: UpdateSetOfNamedTypes [Required]
Updates to the set of destination entity types.
- field update_origin_entity_types: UpdateSetOfNamedTypes [Required]
Updates to the set of origin entity types.
- field update_relationship_types: UpdateSetOfNamedTypes [Required]
Updates to the set of relationship types.
RelationshipType
- pydantic model arcgis.graph.data_model_types.RelationshipType
Represents a relationship named object type for a Knowledge Graph.
Parameter
Description
name
Required String. Name for the Entity Type.
alias
Optional String. The default value is “”.
role
Optional esriGraphNamedObjectRole String. The default value is “esriGraphNamedObjectRegular”.
strict
Optional Boolean. The default value is False.
properties
Optional Dict(String,
GraphProperty
). The default value is {}.field_indexes
Optional Dict(String,
FieldIndex
). The default value is {}.end_points
Optional List[
EndPoint
]. The default value is [].from arcgis.graph import RelationshipType # Example 1: Define a relationship type RelationshipType( name="WorksAt", properties={"name": GraphProperty(name="name")}, field_indexes={"name_index": FieldIndex(name="name_index", is_ascending=True, is_unique=False, fields=["name"])} ) # Example 2: Access a relationship type from the data model data_model = graph.query_data_model() data_model.relationship_types['WorksAt'].properties
- field observed_end_points: list[EndPoint] = []
The observed origin and destination entity type pairs in the database for the relationship type.
SetOfNamedTypes
- pydantic model arcgis.graph.data_model_types.SetOfNamedTypes
Allows users to define the set of named types for a
RelationshipExclusionRule
.Defining a set will exclude the set of named type names from being created in the graph once the exclusion rule is applied. Defining a set_complement will exclude anything other than the set of named type names from being created in the graph once the exclusion rule is applied.
Parameter
Description
set
Optional List of Strings. The default value is [].
set_complement
Optional List of Strings. The default value is [].
from arcgis.graph import SetOfNamedTypes # Example 1: set SetOfNamedTypes(set=["Person","Animal"]) # Example 2: set_complement SetOfNamedTypes(set_complement=["Company"])
UpdateSetOfNamedTypes
- pydantic model arcgis.graph.data_model_types.UpdateSetOfNamedTypes
Allows a user to define named types to add or remove from a
RelationshipExclusionRule
.Parameter
Description
add_named_types
Required List of Strings. Names of types to add to rule.
remove_named_types
Required List of Strings. Names of types to remove from rule.
from arcgis.graph import UpdateSetOfNamedTypes UpdateSetOfNamedTypes(add_named_types=["Individual"], remove_named_types=["Person"])
Graph Types
Entity
- pydantic model arcgis.graph.graph_types.Entity
Represents an entity instance in the knowledge graph
Parameter
Description
type_name
Required String. Name of the
EntityType
id
Optional UUID. The default value is None. If not provided, an id will be assigned to the entity when it is created.
properties
Required Dictionary of Strings and Any values. String is the property name and Any value is the value for that property.
from arcgis.graph import Entity # Example 1: Define an entity Entity( type_name="Company", properties={"name":"Esri"} ) # Example 2: Access an entity in a query response query_result = graph.query("MATCH (n) RETURN n") next(query_result)[0].properties
EntityDelete
- pydantic model arcgis.graph.graph_types.EntityDelete
Allows a user to define which entities to delete from a
EntityType
.Parameter
Description
type_name
Required String. Name of the
EntityType
ids
Required List of UUID or Strings. Ids of the entities to delete.
from arcgis.graph import EntityDelete # Example 1: Provide entity id values manually EntityDelete(type_name="Person", ids=[UUID("783bd422-3hfp-45c7-87aa-8adbbdac0a3d")]) # Example 2: Delete from results of a query results = graph.query("MATCH (n:Person) WHERE n.name CONTAINS "delete" RETURN n.globalid") EntityDelete(type_name="Person", ids=list(results)[0])
Path
- pydantic model arcgis.graph.graph_types.Path
A list of
Entity
andRelationship
objects required to traverse a graph from one entity to another.graph.query("MATCH path=()-[]-() RETURN path LIMIT 1") path = list(result)[0][0] path.path[0] # first entity in path path.path[1] # first relationship in path path.path[-1] # last entity in path
- field path: list[Entity | Relationship] [Required]
The list of entities and relationships in the path.
Relationship
- pydantic model arcgis.graph.graph_types.Relationship
Represents a relationship instance in the knowledge graph
Parameter
Description
type_name
Required String. Name of the
EntityType
id
Optional UUID or String. The default value is None. If not provided, an id will be assigned to the entity when it is created.
origin_entity_id
Required UUID or String. The id of the origin
Entity
in the graph.destiation_entity_id
Required UUID or String. The id of the destination
Entity
in the graph.properties
Optional Dictionary of Strings and Any values. String is the property name and Any value is the value for that property.
from arcgis.graph import Relationship from datetime import datetime from uuid import UUID # Example 1: Define a relationship Relationship( type_name="WorksAt", origin_entity_id=UUID("488bd414-3afd-4547-89aa-4adbbdac0a8d"), destination_entity_id=UUID("783bd422-3hfp-45c7-87aa-8adbbdac0a3d"), properties={"start_date":datetime.fromtimestamp(1578247200000)} ) # Example 2: Access an relationship in a query response query_result = graph.query("MATCH ()-[n]-() RETURN n") next(query_result)[0].properties
RelationshipDelete
- pydantic model arcgis.graph.graph_types.RelationshipDelete
Allows a user to define which relationships to delete from a
RelationshipType
.Parameter
Description
type_name
Required String. Name of the
RelationshipType
ids
Required List of UUID or Strings. Ids of the relationships to delete.
from arcgis.graph import RelationshipDelete # Example 1: Provide relationship id values manually RelationshipDelete(type_name="WorksAt", ids=[UUID("783bd422-3hfp-45c7-87aa-8adbbdac0a3d")]) # Example 2: Delete from results of a query results = graph.query("MATCH ()-[n:WorksAt]-() WHERE n.name CONTAINS "delete" RETURN n.globalid") RelationshipDelete(type_name="WorksAt", ids=list(results)[0])
Transform
- pydantic model arcgis.graph.graph_types.Transform
Allows a user to specify custom quantization parameters for input geometry, which dictate how geometries are compressed and transferred to the server.
Parameter
Description
xy_resolution
Required float.
x_false_origin
Required float.
y_false_origin
Required float.
z_resolution
Required float.
z_false_origin
Required float.
m_resolution
Required float.
m_false_origin
Required float.
Search Types
SearchIndex
- pydantic model arcgis.graph.search_types.SearchIndex
Allows full-text search capability on the graph for a set of properties for each entity or relationship type. Search indexes can be accessed in the
GraphDataModel
.data_model = graph.query_data_model() data_model.search_indexes
- field search_properties: dict[str, SearchIndexProperties] [Required]
The search properties, grouped by type name.
SearchIndexProperties
Response Types
ApplyEditsResponse
- pydantic model arcgis.graph.response_types.ApplyEditsResponse
Response for applying edits to
Entity
orRelationship
in the graph.# Example of a response without errors ApplyEditsResponse( error=None, edits_result={ 'Person': EditResults( add_results=[EditResult(id=UUID('ab913bcb-1781-4137-9513-b3c942c23bc2'), error=None)], update_results=[], delete_results=[] ), 'Company': EditResults( add_results=[EditResult(id=UUID('26419c98-5521-4611-b2c2-196c35acc06d'), error=None)], update_results=[], delete_results=[] ), 'WorksAt': EditResults( add_results=[EditResult(id=UUID('1da2f6fc-e407-4561-97db-bba4745bd803'), error=None)], update_results=[], delete_results=[] ) }, cascaded_deletes={}, relationship_schema_changes={}, cascaded_provenance_deletes=[] ) # Example of a response with errors ApplyEditsResponse( error=Error( error_code=111188, error_message="The destination identifier '{6F445050-0037-4308-8EE4-4B52C83763DC}' was not found." ), edits_result={}, cascaded_deletes={}, relationship_schema_changes={}, cascaded_provenance_deletes=[] )
- field cascaded_deletes: dict[str, list[CascadingRelationshipDelete]] [Required]
The cascade deleted relationships, grouped by type name.
- field cascaded_provenance_deletes: list[CascadingProvenanceDelete] = []
The cascade deleted Provenance entities.
- field relationship_schema_changes: dict[str, RelationshipTypeSchemaChanges] [Required]
The relationship type schema changes, grouped by type name.
ConstraintRuleAddsResponse
- pydantic model arcgis.graph.response_types.ConstraintRuleAddsResponse
Response for adding a
RelationshipExclusionRule
constraint rule.# Example of successful add result ConstraintRuleAddsResponse( error=None, constraint_rule_add_results=[ ConstraintRuleAddResult( name='PersonCanOnlyWorkAtCompany', error=None, warnings=[] ) ] ) # Example of a response with errors ConstraintRuleAddsResponse( error=None, constraint_rule_add_results=[ ConstraintRuleAddResult( name='PersonCanOnlyWorkAtCompany', error=Error( error_code=112237, error_message="Error adding the constraint rule, 'PersonCanOnlyWorkAtCompany', to the data model." ), warnings=[] ) ] )
ConstraintRuleDeletesResponse
- pydantic model arcgis.graph.response_types.ConstraintRuleDeletesResponse
Response for deleting a
RelationshipExclusionRule
.# Example of a response without errors ConstraintRuleDeletesResponse( error=None, constraint_rule_delete_results=[ ConstraintRuleDeleteResult(name='PersonCanOnlyWorkAtCompany', error=None) ] ) # Example of a response with errors ConstraintRuleDeletesResponse( error=None, constraint_rule_delete_results=[ ConstraintRuleDeleteResult( name='PersonCanOnlyWorkAtCompany2', error=Error( error_code=112242, error_message="The constraint rule 'PersonCanOnlyWorkAtCompany2' with role 'REGULAR' does not exist in the data model." ) ) ] )
ConstraintRuleUpdatesResponse
- pydantic model arcgis.graph.response_types.ConstraintRuleUpdatesResponse
Response for updating a
RelationshipExclusionRule
.# Example of a response without errors ConstraintRuleUpdatesResponse( error=None, constraint_rule_update_results=[ ConstraintRuleUpdateResult( name='PersonCanOnlyWorkAtCompany', error=None, warnings=[] ) ] ) # Example of a response with errors ConstraintRuleUpdatesResponse( error=None, constraint_rule_update_results=[ ConstraintRuleUpdateResult( name='PersonCanOnlyWorkAtCompany', error=None, warnings=[ Error( error_code=112225, error_message="A relationship with origin entity type 'Employee', relationship type 'WorksFor', and destination entity type 'Park' is explicitly allowed by relationship exclusion rule 'PersonCanOnlyWorkAtCompany', but not allowed by relationship exclusion rule 'PersonCanOnlyWorkAtCompany3'." ), Error( error_code=112244, error_message='The following entity types do not exist in the data model: [Employee, Park].' ), Error( error_code=112245, error_message='The following relationship types do not exist in the data model: [WorksFor].' ) ] ) ] )
IndexAddsResponse
- pydantic model arcgis.graph.response_types.IndexAddsResponse
Response for adding a
FieldIndex
to aGraphProperty
.# Example of a successful response IndexAddsResponse( error=None, index_add_results=[ IndexAddResult( name='name_index', error=None ) ] ) # Example of a response with errors IndexAddsResponse( error=None, index_add_results=[ IndexAddResult( name='name_index', error=Error( error_code=112047, error_message="Graph Index, 'name_index', already exists." ) ) ] )
IndexDeletesResponse
- pydantic model arcgis.graph.response_types.IndexDeletesResponse
Response for deleting a
FieldIndex
from aGraphProperty
.# Example of a successful response IndexDeletesResponse( error=None, index_delete_results=[ IndexDeleteResult( name='name_index', error=None ) ] ) # Example of a response with errors IndexDeletesResponse( error=None, index_delete_results=[ IndexDeleteResult( name='name_index', error=Error( error_code=112051, error_message="Graph Index, 'name_index', does not exist in the data model." ) ) ] )
NamedObjectTypeAddsResponse
- pydantic model arcgis.graph.response_types.NamedObjectTypeAddsResponse
Response for adding a named object type to the graph.
# Example of a successful response NamedObjectTypeAddsResponse( error=None, entity_add_results=[ NamedObjectTypeAddResult( name='Vehicle', error=None ) ], relationship_add_results=[ NamedObjectTypeAddResult( name='Drives', error=None ) ] ) # Example of a response with errors NamedObjectTypeAddsResponse( error=None, entity_add_results=[ NamedObjectTypeAddResult( name='Vehicle', error=Error( error_code=112092, error_message="The entity or relationship type, 'Vehicle', already exists, please provide a new type name." ) ) ], relationship_add_results=[ NamedObjectTypeAddResult( name='Drives', error=Error( error_code=112092, error_message="The entity or relationship type, 'Drives', already exists, please provide a new type name." ) ) ] )
- field entity_add_results: list[NamedObjectTypeAddResult] [Required]
The list of results for added entity types.
- field relationship_add_results: list[NamedObjectTypeAddResult] [Required]
The list of results for added relationship types.
NamedObjectTypeUpdateResponse
- pydantic model arcgis.graph.response_types.NamedObjectTypeUpdateResponse
Response for updating a named object type in the graph.
# Example of a successful response NamedObjectTypeUpdateResponse(error=None) # Example of a response with errors NamedObjectTypeUpdateResponse( error=Error( error_code=112075, error_message='Updating the name of an entity or relationship type is not allowed.' ) )
NamedObjectTypeDeleteResponse
- pydantic model arcgis.graph.response_types.NamedObjectTypeDeleteResponse
Response for deleting a named object type in the graph.
# Example of a successful response NamedObjectTypeDeleteResponse(error=None) # Example of a response with errors NamedObjectTypeDeleteResponse( error=Error( error_code=112020, error_message="The entity or relationship type definition, 'Vehicle', was not found." ) )
PropertyAddsResponse
- pydantic model arcgis.graph.response_types.PropertyAddsResponse
Response for adding a
GraphProperty
to anEntityType
orRelationshipType
in the graph.# Example of a successful response PropertyAddsResponse( error=None, property_add_results=[ PropertyAddResult( name='age', error=None ) ] ) # Example of a response with errors PropertyAddsResponse( error=None, property_add_results=[ PropertyAddResult( name='age', error=Error( error_code=112043, error_message="Graph property, 'age', already exists in data model." ) ) ] )
- field property_add_results: list[PropertyAddResult] [Required]
The list of results for the added properties.
PropertyUpdateResponse
- pydantic model arcgis.graph.response_types.PropertyUpdateResponse
Response for updating a
GraphProperty
in the graph.# Example of a successful response PropertyUpdateResponse(error=None) # Example of a response with errors PropertyUpdateResponse(error=Error(error_code=112068, error_message="Graph property, 'current_age', does not exist in data model."))
PropertyDeleteResponse
- pydantic model arcgis.graph.response_types.PropertyDeleteResponse
Response for deleting a
GraphProperty
in the graph.# Example of a successful response PropertyDeleteResponse(error=None) # Example of a response with errors PropertyDeleteResponse(error=Error(error_code=112068, error_message="Graph property, 'age', does not exist in data model."))
SyncDataModelResponse
- pydantic model arcgis.graph.response_types.SyncDataModelResponse
Response for syncing the
GraphDataModel
usingsync_data_model()
.# Example of a successful response SyncDataModelResponse(error=None) # Example of a response with errors SyncDataModelResponse( error=Error( error_code=113005, error_message="The service's graph data source does not support the operation." ) )
UpdateSearchIndexResponse
- pydantic model arcgis.graph.response_types.UpdateSearchIndexResponse
Response for updating a
SearchIndex
usingupdate_search_index()
.# Example of a successful response UpdateSearchIndexResponse(error=None) # Example of a response with errors UpdateSearchIndexResponse( error=Error( error_code=112093, error_message="The entity or relationship type, 'NotAType', does not exist." ) )