Skip to main content

Use ArcPy in a notebook

Several ArcPy modules are available in ArcGIS Notebooks through the Advanced notebook runtime.

With the ArcPy site package, you can perform geographic data analysis, conversion, and management. ArcPy allows you to programmatically run all ArcGIS standard geoprocessing tools and provides helper functions and classes.

Learn more about ArcPy

To use ArcPy in a notebook, ArcGIS Notebook Server must be licensed with the Advanced license, and users must have the privilege to create and run ArcPy notebooks.

Get started with ArcPy in a notebook

To use ArcPy in a notebook, import its library by running a cell with the following lines:

import arcpy
arcpy.GetInstallInfo()['Version']

To access or share content in your organization, you must be signed in. In ArcGIS Notebooks, you can sign in to your organization without explicitly providing a URL, username, or password by using the following code:

arcpy.SignInToPortal("notebook")

Tip:

While most ArcPy tools work with Linux style paths, it is recommended that you use Windows formatted paths for files and directories when running notebooks in a Windows container, for example, C:\arcgis\home. This ensures that ArcPy tools and workflows will run successfully.

The workspace path can also be constructed dynamically. For example:

import os
import arcpy
drive = os.path.splitdrive(os.getcwd())[0]
home_dir = os.path.join(drive + os.sep, "arcgis", "home")
arcpy.env.workspace = home_dir

ArcPy modules

The modules below are included with ArcPy in ArcGIS Notebooks.

  • The Data Access module, arcpy.da allows control of the edit session, edit operation, improved cursor support (including faster performance), functions for converting tables and feature classes to and from NumPy arrays, and support for versioning, replicas, domains, and subtypes workflows.

  • The Geocoding module, arcpy.geocoding, allows you to perform various geocoding operations, including finding the location of a place or address, finding the closest place or address to a given location, or generating a set of autocomplete suggestions for partial input.

  • The Image Analysis module, arcpy.ia, allows you to manage and process imagery and raster data. The module also includes geoprocessing and raster processing automation functionality provided by the ArcGIS Image Analyst extension.

  • The Mapping module, arcpy.mp, allows you to manipulate the contents of existing projects (.aprx) and layer files (.lyrx) and to create and modify maps, layouts, and reports.

  • The Metadata module, arcpy.metadata, allows you to explore information describing your maps and data and automate your workflows, particularly for managing standards-compliant geospatial metadata.

  • The Network Analyst module, arcpy.nax, allows you to work with network analysis functionality provided with the ArcGIS Network Analyst extension.

    The legacy module arcpy.na is not included with ArcGIS Notebooks.

  • The Sharing module, arcpy.sharing module allows you to automate sharing workflows. Use it to create a sharing draft, which is a configurable set of properties for a web layer, web tool and geoprocessing service, map service, or image service.

  • The Spatial Analyst module, arcpy.sa, provides access to all the geoprocessing tools available in the Spatial Analyst toolbox as well as other functions and classes that allow you to automate your raster processing workflows.

ArcPy functions

ArcPy provides a number of functions to better support workflows using Python. In addition to the function groups listed in this topic, all geoprocessing tools can be accessed as ArcPy functions.

For more information on the functions included in each group, see An overview of ArcPy functions in the ArcGIS Pro documentation.

The following groups of function are included with ArcGIS Notebooks:

  • ArcGIS Online / Portal functions

  • Data store functions

  • Describing data functions

  • Environment functions

  • Field functions

  • General functions, except ListPrinterNames

  • General data functions

  • Geometry functions

  • Licensing and installation functions

  • Listing data functions, except ListVersions

  • Logging functions

  • Packaging functions

  • Progress dialog functions

  • Raster functions

  • Spatial reference and transformation functions