Hi David,
I wrote a simple script (and a toolbox in the reply below. Modified from CreateWebLayerSDDraft—ArcPy | Documentation) that creates separate hosted feature layers on an AGOL/Poral account. The script py file is attached to this post.
- The script lists all layers in an ArcGIS Pro project (aprx), and then publishes each layer (which is a feature class) as a separate service
- Run this script with Python for ArcGIS Pro (e.g. v3.6.9).
- Fill lines 4-6 with your inputs: aprx path, map name (in aprx) and workspace path.
- Script will publish layers to your active portal/AGOL account as specified in your ArcGIS Pro.
- sddraft and sd files are saved to a local folder (user to provide path for folder, line 6). If you rerun the script make sure to delete these files.
- If you rerun this script make sure to delete existing service with the same name from your account.
- The service name will be identical to the layer's name. To change the service name insert a new name in line 17 (replace the second 'lyr' with the new name).
import arcpy
aprx = arcpy.mp.ArcGISProject(r'C:\Users\...Project.aprx')
map_name = 'Map'
workspace = r'C:\Users\...\folder'
m = aprx.listMaps(map_name)[0]
layers = m.listLayers('*')
for lyr in layers:
if lyr.isFeatureLayer:
sddraft = workspace+'\\'+str(lyr)+'.sddraft'
sd = workspace+'\\'+str(lyr)+'.sd'
arcpy.mp.CreateWebLayerSDDraft(lyr, sddraft, lyr, 'MY_HOSTED_SERVICES', 'FEATURE_ACCESS')
arcpy.StageService_server(sddraft, sd)
arcpy.UploadServiceDefinition_server(sd, 'My Hosted Services')
print (str(lyr)+': Published successfully')