ArcGIS Python API

ENV 859 - Geospatial Data Analytics   |   Fall 2023   |   Instructor: John Fay  

In the last session on web services, REST, and APIs, we revealed that virtually all resources hosted on ArcGIS Online (enterprise or organizational) are accessible via the service’s REST endpoint. Thus, by passing carefully crafted URLs to ArcGIS servers, we could access, query, display, and even download remotely hosted data to suit our needs. You likely noticed, however, that ESRI’s REST API, while powerful and fully documented, is somewhat complex and not very Pythonic.

Fortunately for us, a few years ago, some ESRI developers decided to develop a nicer Python interface to this REST interface, and thus was born the ArcGIS API for Python, aka the “ArcGIS Python API” (still needs a catchier name, IMO). In fact, you can see it’s full developmental history via its GitHub repository!

Now, this is all not to say that learning the ArcGIS Python API is a piece of cake; the library does make accessing AGOL data and analytical tools much easier, but it’s fairly complex and fast-evolving. In fact, what’s covered here may be outdated within weeks. Still, that should never stop us. So moving forward, we’ll explore the key components ArcGIS Python API, seeking not to know how to do everything with the library, but instead, learning its overall structure, documentation, and generally how to speed your path to leveraging this tool’s abilities to serve your needs.

From my experience using this library, I’ve narrowed in on the following essential features to know:

  • Locating and using the API’s documentation: the guide, examples, and references
  • Using the API’s GIS object to connect to ArcGIS online (either anonymously or via your AGOL account credentials)
  • Searching for AGOL data and getting the data into your Python coding environment
  • The hierarchy of data objects: items, feature services, feature layers, feature sets, and spatial dataframes
  • Working with retrieved data objects to get what you want
  • Creating maps
  • Saving data to local files

Set up:

  • Fork and clone the https://github.com/ENV859/ArcGIS-PythonAPI repository. As you might expect, this contains a number of Python notebooks containing examples for learning the concepts mentioned above. Included is a link to open Jupyter using your ArcGIS Pro default environment (“arcgispro-py3”).

Recording Highlights

6.5.1 Intro & Connecting to AGOL

Time Topic
0:00 Introduction & Setup
3:55 Finding additional tutorials & documentation
5:00 Navigating documentation: how to teach yourself
9:37 Getting started: connect to AGOL via the GIS object
11:30 Creating an anonymous connection with GIS()
13:01 Exploring the GIS object: properties and methods
14:15 Creating an authenticated connection with GIS('home')
17:40 Authenticating via username and password

6.5.2 Accessing AGOL content

Time Topic
1:00 Searching for AGOL data via the web & filtering results
2:20 - Navigating a dataset’s resource page
3:30 - Review: ESRI’s REST API interface
5:09 Creating an authenticated connection to AGOL
5:28 Learning how to search for content: gis.content.search()
9:15 Executing a query to search for data
10:15 - Enabling the search to go beyond Duke’s portal with outside_org=True
11:00 - Increasing the number of results with max_items=1000
12:55 - Filtering results with item_type =
13:48 Working with the search result
16:10 Getting and using an object’s item it

6.5.3 Working with AGOL Content

6.5.4 Demos & Raster Content