How to access layer using feature service URL/path

09-27-2023 04:50 PM
Labels (2)
New Contributor III

Hey there,

I am trying to access a feature layer within my portal using the layers path. I have been accessing the data within visual studio code using the feature layers ID like this: 


feature_service_layer = gis.content.get('964b4b7b112347e9ff76609bfc75432').layers[0]


I'd like to make a Geo Processing tool out of the code. The tool would accept the parameter under the format of  the URL which would be something along the lines of:  ''


I have tried to add the url to the code but it is unsuccessful. Here is what it looked like (I also tried the .Search method):


feature_service_layer = gis.content.get(

feature_service_layer =


If I can't use these methods how am I supposed to take a feature layer in as a parameter and access its data?


Any help is appreciated. 


0 Kudos
3 Replies
New Contributor III


I have found that this actually does work : 

feature_service_layer ='')

But it gives me the content as a a list which has proven hard to get to a sdf.

I tried :

sdf = pd.DataFrame.spatial.from_layer(feature_service_layer[0])

 but received this error:

Traceback (most recent call last):
  File "y:\Zack\Other_Projects\Python_projects\Duplicate Stand ID Tool\", line 33, in <module>
    sdf = pd.DataFrame.spatial.from_layer(feature_service_layer[0])
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\geo\", line 3077, in from_layer
    raise Exception("Could not load the dataset: %s" % str(e))
Exception: Could not load the dataset: 'Item' object has no attribute 'filter'
PS Y:\Zack\Other_Projects\Python_projects\Duplicate Stand ID Tool>
0 Kudos
Esri Regular Contributor

Have you considered just using FeatureLayer? If you know ahead of time what the URL is, you don't have to search for it.

from arcgis import GIS
from arcgis.features import FeatureLayer

gis = GIS()
url = "https://urlforlayer/0"
fl = FeatureLayer(url, gis)
0 Kudos
New Contributor III

I tried that. Similar issue. I can access the layer but not the table.

feature_service_item = arcgis.features.FeatureLayer('')

sdf = pd.DataFrame.spatial.from_layer(feature_service_item)


Exception: Could not load the dataset: Cannot perform query. Invalid query parameters.


0 Kudos