The ItemProperties Class with the ArcGIS API for Python for ArcGIS Online or Portal

Table of Contents

Introduction

The ArcGIS API for Python as of version 2.1.0.3 added Dataclasses for adding and updating items. These were ItemProperties, CreateServiceParameter, SpatialFilter, and ViewLayerDefParameter. In this post we will assess the ItemProperties class.

The item_properties dictionary

The usual way to use item properties is to create a dictionary of key-value pairs. add() and update() methods that utilise an item_properties parameter would accept this dictionary, and set object properties such as title, item type, summary, description, and tags for examples. The ContentManager add() method is an instance of this scenario. As of creating this post (25/07/2024), the documentation for the add() method still stipulates that the item_properties is a required dictionary, albeit the dictionary can be empty. However, you can also use the ItemProperties class with the item_properties parameter as of 2.1.0.3.

I have a zipped folder named FDM_DICTIONARY.zip.

And the components of a Shapefile within that zipped folder.

The below code snippet is an example with using a dictionary to add a Shapefile item to ArcGIS Online using the ArcGIS API for Python. The add() method in the documentation has information on other key-value pairs you can use for the item_properties dictionary.

				
					from arcgis.gis import GIS

agol = GIS("home")

## path to a zipped folder containing a shapefile(s)
shp_zip = r"C:\Path\to\Shapefiles\FDM_DICTIONARY.zip"

## these properties will be set on the item upon creation
## here we use a dictionary to set the properties using key-value pairs
item_properties = {
    "title" : "SHAPEFILE_ADDED_WITH_DICTIONARY",
    "tags" : ["SHP", "DICTIONARY"],
    "snippet" : "This shp was added using a dictionary for item_properties", #summary
    "description" : "Added as part of a blog post example by FDM",
    "licenseInfo" : "No known restrictions", # terms of use
    "type" : "Shapefile"
}

## add the shapefile to acrgis online using the ContentManager add() method
agol.content.add(
    item_properties = item_properties,
    data = shp_zip
)

				
			

After running the code above we have a new Shapefile Item added to our ArcGIS Online Content. The title of the Shapefile item has honoured the title property from the dictionary.

When we click in to the Shapefile item we can see that the other properties were also set for our summary, description, terms of use, and tags.

The ItemProperties class

The ItemProperties class was introduced in version 2.1.0.3. The parameters to create an ItemProperties object are comprises of those properties of an item that are available using the add() and update() methods. Check out the documentation for the full list of parameters.

We need to import the ItemProperties class.

				
					## import the ItemProperties class
from arcgis.gis import GIS, ItemProperties

agol = GIS("home")
				
			

I have a zipped folder named FMD_ITEMPROPERTIES.zip

And the components of a Shapefile within that zipped folder.

We perform the same action with the ContentManager add() method that we above to add a Shapefile to our ArcGIS Online, but this time, instead of supplying a dictionary for the item_properties parameter, we are supplying an ItemProperties object.

				
					## path to a zipped folder containing a shapefile(s)
shp_zip = r"C:\Path\to\Shapefiles\FDM_ITEMPROPERTIES.zip"

## these properties will be set on the item upon creation
## here we use the ItemProperties class and supply the property details as
## parameters
item_properties = ItemProperties(
    title = "SHAPEFILE_ADDED_WITH_ItemProperties",
    tags = ["SHP", "ItemProperties"],
    snippet = "This shp was added using an ItemProperties object for item_properties",
    description = "Added as part of a blog post example by FDM using ItemProperties class",
    license_info = "No known restrictions",
    item_type = "Shapefile"
)

## add the shapefile to acrgis online using the ContentManager add() method
agol.content.add(
    item_properties = item_properties,
    data = shp_zip
)
				
			

After running the code above we have a new Shapefile Item added to our ArcGIS Online Content. The title of the Shapefile item has honoured the title parameter from the ItemProperties object.

When we click in to the Shapefile item we can see that the other properties were also set for our summary, description, terms of use, and tags.

Learn more about adding and updating items with our training course...

Unlock the full potential of ArcGIS Online by mastering the art of efficient Content Management with the ArcGIS API for Python. In this comprehensive course, you will embark on a journey to streamline your geospatial workflows, enhance data organization, and maximize the impact of your ArcGIS Online platform.

Geospatial Professionals, GIS Analysts, Data Managers, and enthusiasts will discover the power of automation and script-based operations to efficiently manage content in ArcGIS Online. Throughout this course, you will gain practical, hands-on experience in leveraging the ArcGIS API for Python to perform a wide range of content management tasks with ease.

Leave a Comment

Your email address will not be published. Required fields are marked *