HOW TO

Batch download hosted feature layers from ArcGIS Online using ArcGIS API for Python

Last Published: March 31, 2026

Summary

This script uses ArcGIS API for Python to back up hosted feature layers in an ArcGIS Online organization by exporting each hosted feature service to a file geodatabase and downloading it to a specified local output folder.

Note:
This script must be run in an ArcGIS Notebook in ArcGIS Pro because it downloads items to the machine’s local file system. Notebooks in ArcGIS Online run in an isolated hosted container and cannot write directly to local paths.

Procedure

  1. Create a new Notebook in ArcGIS Pro. Refer to ArcGIS Pro: How to use ArcGIS Notebooks in ArcGIS Pro for instructions.
  2. Import the necessary modules. 
from arcgis.gis import GIS
import os
  1. Enter ArcGIS Online credentials.
gis = GIS("https://www.arcgis.com", "username", "password")
  1. Specify the output folder path on the local machine.
output_folder = r""
  1. Search for all the layers in the organization.
hosted_feature_layers = gis.content.search(query=f'type:"Feature Service"', max_items=-1)
  1. List all the layers in the organization.
for myLayer in hosted_feature_layers:
print(f"Title:{myLayer.title}, Item ID:{myLayer.id}, Owner:{myLayer.owner}, ItemType:{myLayer.type}" )
  1. Export each layer to a file geodatabase and download locally
for layer in hosted_feature_layers:
   try:
      export_layer = layer.export(layer.title, "File Geodatabase")
      export_layer.download(save_path=output_folder)
      print(f"Downloaded: {layer.title}")
   except Exception as e:
      print(f"Failed for {layer.title}: {e}")

Article ID: 000040505

Software:
  • ArcGIS Pro
  • ArcGIS Online
  • ArcGIS API for Python

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options