arcgis.apps.itemgraph module

create_dependency_graph

arcgis.apps.itemgraph.create_dependency_graph(gis: GIS, item_list: list[Item, str], outside_org: bool = True, **kwargs)

Creates an ItemGraph from a list of items. The function recursively explores the dependencies of each item that is part of the organization, encompassing the full dependency tree of each source item.

Note

If the outside_org argument is set to True, items external to the organization are incuded in the results, but are not explored for dependencies.

Parameter

Description

gis

Required GIS object. The GIS instance that the graph is associated with.

item_list

Required list of items or Item ID values to include in the graph.

outside_org

Optional boolean.

  • When True, items outside of the organization will be included in the graph (but still not explored for their dependencies). Default is True.

  • When False, only items owned by users in the org will be included in the graph.

In addition to explicitly named parameters, this function supports optional key word arguments:

kwargs

Description

include_reverse

Optional boolean.

  • When True, the graph will include reverse relationships found found when calling the related_items() method on an item with the item.related_items(direction=”reverse”) argument

  • When False, only includes item.related_items(direction=”forward”) relationships

Returns:

An ItemGraph with all of the relevant items and relationships.

load_from_file

arcgis.apps.itemgraph.load_from_file(path: str, gis: GIS = None, include_items: bool = True)

Loads a graph from a file in GML format. The graph should have been written to the file using the write_to_file method.

Parameter

Description

path

Required string. The path to the GML file to load the graph from.

gis

Required GIS object. The GIS instance that the graph is associated with. If not provided, the active GIS will be used, if available. Must be the same GIS as the one used to create the graph.

include_items

Optional boolean.

  • When True, the ItemNode instances will include the item instances as well. Otherwise, items are retrieved as needed. Default is True.

  • When False, item instances are not included.

Note

Best practice is to set to False on very large graphs.

Returns:

An ItemGraph instance.

ItemGraph

class arcgis.apps.itemgraph.ItemGraph(gis: GIS = None, digraph: DiGraph = None)

An ItemGraph is a directional dependency graph that represents relationships between items. An item is deemed to be dependent upon another item if the other item appears in the first item’s data, structure, or dependent items property- the relationship type of this graph can be intepreted as “Item A needs Item B to exist”. Users can retrieve an item in the graph via an item’s item ID (assuming the item has been indexed into the graph), at which point they’ll get an ItemNode to work with. Users can manually add items or relationships to the graph if desired, but most of the time this will be taken care by other functions, such as the create_dependency_graph function. The graph is built on top of the NetworkX DiGraph class, meaning it also inherits all of its methods and properties as well.

Parameter

Description

gis

Required GIS. The GIS instance that the graph is associated with.

add_dependencies(item_list: list[Item, str], outside_org: bool = True, **kwargs)

Adds a list of items to the graph and their dependencies. The function recursively explores the dependencies of each item that is part of the organization, encompassing the full dependency tree of each source item.

Note

If the outside_org argument is set to True, items external to the organization are incuded in the results, but are not explored for dependencies.

Parameter

Description

item_list

Required list of items or Item ID values to include in the graph.

outside_org

Optional boolean.

  • When True, items outside of the organization will

be included in the graph (but still not explored for their dependencies). Default is True. * When False, only items owned by users in the org will be included in the graph.

In addition to explicitly named parameters, this function supports optional key word arguments:

kwargs

Description

include_reverse

Optional boolean.

  • When True, the graph will include reverse relationships found

found when calling the related_items() method on an item with the item.related_items(direction=”reverse”) argument * When False, only includes item.related_items(direction=”forward”) relationships

add_item(itemid: str, item=None)

Adds an item to the graph. The item ID is required, but the item itself is optional. Creates an ItemNode with the item ID and item. Will usually be called by other functions and not by users. Note that this does not add any relationships to the graph.

Parameter

Description

itemid

Required string. The item ID of the item to add.

item

Optional Item. An instance of the item to add.

add_relationship(parent: str, child: str)

Adds a relationship to the graph. This relationship is directional: the parent item contains the child item, so the parent item is dependent upon the child. If either item is not already in the graph, they will be automatically added.

Note

Relationships cannot go both ways- an item cannot be both dependent upon and a dependency of the same item. Attempting to add a relationship will fail if the inverse already exists.

Parameter

Description

parent

Required string. The item ID of the parent item.

child

Required string. The item ID of the child item.

all_items(out_format: str = 'node')

Returns a list of the item ID’s of all items in the graph.

Parameter

Description

out_format

Required string. The format of items in the list. Default is node. Options:

  • node

  • item

Returns:

  • List of item if out_format=”item”

  • List of itemnode objects if out_format=”node”

delete_item(itemid: str)

Deletes an item from the graph. Associated relationships will also be removed.

Parameter

Description

itemid

Required string. The item ID of the item to remove.

delete_relationship(parent: str, child: str)

Deletes a relationship from the graph. The relationship is directional, so it is important to properly specify which item is the parent and which is the child.

Parameter

Description

parent

Required string. The item ID of the parent item.

child

Required string. The item ID of the child item.

get_node(itemid: str)

Method gets an ItemNode instance for the item contained in the graph with the given item ID. None will be returned if the item is not in the graph.

Parameter

Description

itemid

Required string. The item ID of the item node to retrieve.

Returns:

An ItemNode instance.

write_to_file(location: str)

Writes the graph to a file in GML format.

..note::

Method strictly writes the ID’s and edges of the graph. No information about the items themselves is included.

Parameter

Description

location

Required string. The path to write the file to.

ItemNode

class arcgis.apps.itemgraph.ItemNode(graph, itemid: str, item=None)

An ItemNode is a node in an ItemGraph. It represents an item in the graph and contains methods to interact with the graph and other items in the graph. It is not intended to be created directly by the user, but rather as a part of the ItemGraph class. The nodes are very simple- the only properties they contain are the item ID, a reference to the graph they’re tied to, and in most cases, a reference to the item they’re tied to. Cases where an item will not be included: 1. The item does not exist, or is not accessible to the user (e.g. outside of the organization) 2. The graph is being reconstructed from a list of item ID’s and the item has not been fetched yet In this second case, other methods will be used to fetch the item when needed, in order to maximize efficiency when creating a large graph.

Parameter

Description

graph

Required ItemGraph. The graph instance that the node is associated with.

itemid

Required String. The item ID of the item that the node represents.

item

Optional Item. An instance of the item that the node represents.

contained_by(out_format: str = 'node')

Compiles all of the items that directly contain this item. Can be returned in either the format of a list of item ID’s, a list of item instances, or a list of graph nodes.

Parameter

Description

out_format

Optional string. Options are “id”, “item”, and “node”. Default is “id”.

Note

If this is set to “item”, and an item instance is not accessible, the item ID will be returned for that item instead.

Returns:

A list of item ID’s or items.

contains(out_format: str = 'node')

Compiles all of the items that this item directly contains. Can be returned in either the format of a list of item ID’s, a list of item instances, or a list of graph nodes.

Parameter

Description

out_format

Optional string. Options are “id”, “item”, and “node”. Default is “id”.

Note

If this is set to “item”, and an item instance is not accessible, the item ID will be returned for that item instead.

Returns:

A list of item ID’s or items.

required_by(out_format: str = 'node')

Compiles a deep list of all items that require this item to exist. For example, if this item is a Feature Service found in a WebMap that is then itself found in a Dashboard, both of those items will be in the output list, on the condition that they have been indexed into the ItemGraph. Can be returned in either the format of a list of item ID’s, a list of item instances, or a list of graph nodes.

Parameter

Description

out_format

Optional string. Options are “id”, “item”, and “node”. Default is “id”.

Note

If this is set to “item”, and an item instance is not accessible, the item ID will be returned for that item instead.

Returns:

A list of item ID’s or items.

requires(out_format: str = 'node')

Compiles a deep list of all items that this item requires to exist. For example, if an item contains a WebMap item that itself contains a Feature Service item, then both of them will be returned in the output list. Can be returned in either the format of a list of item ID’s, a list of item instances, or a list of graph nodes.

Parameter

Description

out_format

Optional string. Options are “id”, “item”, and “node”. Default is “id”.

Note

If this is set to “item”, and an item instance is not accessible, the item ID will be returned for that item instead.

Returns:

A list of item ID’s or items.

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