Ensure the "Allow others to export to different formats" setting is checked in the Settings tab of the hosted feature layer's item page.
To download a hosted layer programmatically, the most efficient workflow involves using the arcgis library to export the layer to a portable format (like a File Geodatabase) on the server, downloading that file, and then using arcpy for local processing.
Once the file is on your machine, use ArcPy to extract the data into your working environment or convert it into a different format. arcpy download hosted feature layer
How to Download Hosted Feature Layers with ArcPy and Python Downloading hosted feature layers from ArcGIS Online (AGOL) or ArcGIS Enterprise is a critical task for maintaining local backups, performing offline spatial analysis, or integrating web data into desktop workflows. While excels at local data management, it is typically used in tandem with the ArcGIS API for Python to bridge the gap between web GIS and your local machine. The Hybrid Approach: Web API + ArcPy
If your layer contains photos or files, use the Create Replica method via the REST API or the ArcGIS API for Python to ensure they are included in the download. Ensure the "Allow others to export to different
If you do not want to use the arcgis module, you can sometimes use ArcPy’s FeatureClassToGeodatabase tool by passing the of the hosted service directly as the input.
import arcpy import zipfile # Path to the downloaded zip zip_file = os.path.join(download_path, "Export_Your_Layer_Name.zip") extract_to = r"C:\Data\WorkingGDB" # Extract the FGDB from the zip file with zipfile.ZipFile(zip_file, 'r') as zip_ref: zip_ref.extractall(extract_to) # Set workspace to the newly extracted geodatabase # Note: The FGDB name inside the zip usually matches the export title gdb_path = os.path.join(extract_to, "Export_Your_Layer_Name.gdb") arcpy.env.workspace = gdb_path # List and process layers feature_classes = arcpy.ListFeatureClasses() for fc in feature_classes: print(f"Processing local feature class: {fc}") # Example: Copying to a master database arcpy.management.CopyFeatures(fc, rf"C:\Master\Data.gdb\{fc}") Use code with caution. How to Download Hosted Feature Layers with ArcPy
Before ArcPy can "see" the data, you must extract it from the cloud. The following script authenticates with your portal, searches for a specific item, exports it to a .zip containing a File Geodatabase (FGDB), and downloads it to a local folder.