Select to view content in your preferred language

How do I know which properties an item has?

814
4
Jump to solution
09-16-2024 12:20 PM
Labels (2)
RandyMcGregor_BMcD
Frequent Contributor

This is a VERY general question, but it would be very helpful to get this figured out. Sometimes, when I enter "item.properties" I get nice list of properties. And sometimes, I get nothing. 'check_item' below is a feature service view. I wanted to know which properties I have access to and the 'properties' attribute says 'None.'

print(check_item.properties)

None

There are many I know of: 'title' 'shared_with' 'snippet' etc... How does one acquire a list of the available properties of an item? jupyter does not seem to have autofill.

Thank you,

R

0 Kudos
1 Solution

Accepted Solutions
Clubdebambos
MVP Regular Contributor

Hi @RandyMcGregor_BMcD 

The documentation states that Item objects have a base of a dictionary. 

 

from arcgis.gis import GIS

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

## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID") 

## print each property name
for p in item.keys():
    print(p)

 

Want to see the keys and values printed neatly...

from arcgis.gis import GIS
import json

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

## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID") 

## print property name : value
print(json.dumps(item, indent=4))

 

As mention by @DavidSolari, you can use dir(), this will return beyond the item dictionary properties and include the class properties and methods amongst others.

from arcgis.gis import GIS

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

## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID") 

## dir() will return the dictionary properties, class properties and methods, dunder methods and properties
print(dir(item))

  

~ learn.finaldraftmapping.com

View solution in original post

4 Replies
DavidSolari
MVP Regular Contributor

When in doubt, dir is your friend!

Clubdebambos
MVP Regular Contributor

Hi @RandyMcGregor_BMcD 

The documentation states that Item objects have a base of a dictionary. 

 

from arcgis.gis import GIS

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

## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID") 

## print each property name
for p in item.keys():
    print(p)

 

Want to see the keys and values printed neatly...

from arcgis.gis import GIS
import json

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

## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID") 

## print property name : value
print(json.dumps(item, indent=4))

 

As mention by @DavidSolari, you can use dir(), this will return beyond the item dictionary properties and include the class properties and methods amongst others.

from arcgis.gis import GIS

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

## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID") 

## dir() will return the dictionary properties, class properties and methods, dunder methods and properties
print(dir(item))

  

~ learn.finaldraftmapping.com
RandyMcGregor_BMcD
Frequent Contributor

Thank you. I appreciate it. I'm going to fess up here. I find the documentation extremely difficult to understand. I basically just hunt and use trial and error until something works. It's designed for coders of course and that's understandable. I wonder if there's a way people like me who work with notebooks and usually can get them to work to get background that would make the documentation more readable? It seems like a lot of scanning is required, few links...

0 Kudos
RandyMcGregor_BMcD
Frequent Contributor

This works perfectly (Thank you!):

 

from arcgis.gis import GIS

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

## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID") 

## print each property name
for p in item.keys():
    print(p)

 

 

This, using the same item id, does not:

from arcgis.gis import GIS
import json

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

## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID") 

## print property name : value
print(json.dumps(item, indent=4))

RandyMcGregor_BMcD_0-1726576258138.png

for 'item' I entered a feature service view's item id.

0 Kudos