Get All Content Item Tags in ArcGIS Online using the ArcGIS API for Python

Table of Contents

Introduction

The ArcGIS API for Python is a powerful Python library that allows users to interact with and automate tasks in ArcGIS Online (or Portal). The API is excellent for programmatically creating, maintaining, and updating components of ArcGIS Online such as content items. In this post we will use the ArcGIS API for Python to retrieve a list of all content item tags used within the Organisation.

Tags in ArcGIS Online are keywords that users can associate with their items, such as maps, apps, feature services, and other resources. These tags help organise and categorise content, making it easier to find content within the ArcGIS Online.

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.

arcgis modules

The API provides access to your organisations ArcGIS Online via the GIS class in the gis module. This GIS class is the gateway to ArcGIS Online. 

				
					## import GIS which provides the gateway entry to your AGOL
from arcgis.gis import GIS


				
			

Accessing ArcGIS Online

Our first port of call is to access your ArcGIS Online via the GIS class. There are a handful of ways to achieve access, if you are logged into your ArcGIS Online in ArcGIS Pro you can simply use "home", otherwise, another common way is to provide the ArcGIS Online URL, followed by your username and password. This is handled in the code snippet above.

				
					## Access AGOL
agol = GIS("home")
				
			
				
					## Access AGOL
agol = GIS(
    url = "https://your_organisation.maps.arcgis.com/",
    username = "Your_Username",
    password = "Your_Password"
)
				
			

Get a the set of tags

We will use Python set comprehension along with the ContentManager search() method to access each item in your Organisation and return a unique set of tags. You can set the max_items parameter to suit your needs, and you can alter the query or other search parameters to target specific item types for example.

				
					## get a set containing all tags
tags = {tag for item in agol.content.search(query="", max_items=1000) for tag in item.tags}

## print to screen
print(tags)
				
			

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.

All the code in one place

You can find the entire code workflow below.

				
					from arcgis.gis import GIS

## access agol
agol = GIS("home")

## get a set containing all tags
tags = {tag for item in agol.content.search(query="", max_items=1000) for tag in item.tags}

## print to screen
print(tags)
				
			

Leave a Comment

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