get storage size of feature service

2079
4
Jump to solution
11-29-2016 11:12 PM
AlistairFox
Occasional Contributor

I know you can get a users storage quota and usage but how do you find out the individual feature class storage of an item using portal py or another method?

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

The PortalPy module is still around but it is being superseded by the ArcGIS Python API.  I don't believe what you ask is doable directly or only through PortalPy, but you can do it using the new ArcGIS Python API:

>>> import arcgis
>>>
>>> url = # url of Portal or Organizational AGOL
>>> username = 
>>> password = 
>>> item_name = # name of item for looking up size
>>> 
>>> gis = arcgis.gis.GIS(url, username, password)
>>> item = gis.content.search(item_name)[0] # assumes unique name so only 1 item returned
>>> item_full = gis.content.get(item.id)
>>> item_full.size
3850776
>>>

Personally, I got a bit of heartburn over how items are returned when using search in the new API, but that is a soapbox for another venue and another day.

If you don't or can't utilize the ArcGIS Python API, the guts of the code from the Example: Copy content can be used to write a script for accessing an item's size.

View solution in original post

4 Replies
JoshuaBixby
MVP Esteemed Contributor

The PortalPy module is still around but it is being superseded by the ArcGIS Python API.  I don't believe what you ask is doable directly or only through PortalPy, but you can do it using the new ArcGIS Python API:

>>> import arcgis
>>>
>>> url = # url of Portal or Organizational AGOL
>>> username = 
>>> password = 
>>> item_name = # name of item for looking up size
>>> 
>>> gis = arcgis.gis.GIS(url, username, password)
>>> item = gis.content.search(item_name)[0] # assumes unique name so only 1 item returned
>>> item_full = gis.content.get(item.id)
>>> item_full.size
3850776
>>>

Personally, I got a bit of heartburn over how items are returned when using search in the new API, but that is a soapbox for another venue and another day.

If you don't or can't utilize the ArcGIS Python API, the guts of the code from the Example: Copy content can be used to write a script for accessing an item's size.

AlistairFox
Occasional Contributor

thanks that helps. I've installed ArcGIS Python and got this running through the Jupyter notebook. Works well. Got your code above working through this too.

Only issue I've hit is trying to get the same code running from a standalone python script. I get the following error. 

gis = arcgis.gis.GIS(url, username, password)
AttributeError: 'module' object has no attribute 'gis'

Running this under Python 2.7. works fine in a notebook. Any ideas?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

From ArcGIS Python API Install and setup:

Install the latest version of Anaconda for Python (for Python 3.5), if you don't already have conda. The ArcGIS Python API requires Python 3.

If you have installed ArcGIS Pro 1.3, you already have conda and you can use that instead of downloading Anaconda.

Do you have ArcGIS Pro installed?  There is at least one other Python interpreter on your machine, a Python 3 interpreter, because it wouldn't be working at all otherwise.  Try running the script from the Python installation that Jupyter notebook it using, not a Python 2.7 installation.

0 Kudos
JohnBoyles
New Contributor

thanks a lot for this!

0 Kudos