AGOLNotebookManager
- class arcgis.gis.agonb.AGOLNotebookManager(url: str, gis: GIS)
Bases:
object- property containers: ContainerManager
Provides the ability to manage containers and the notebooks within them
- Returns:
- property data_access: NotebookDataAccess
Provides access to managing files stored on notebook server.
- Returns:
NotebookDataAccessobject
- property instance_preferences: InstancePreference
Deprecated since version 2.4.4: Removed in: 2.5.0. This endpoint is no longer supported by ArcGIS Online Notebooks.
Deprecated since version 2.4.4: Removed in: 2.5.0. This endpoint is no longer supported by ArcGIS Online Notebooks.
Provides information about the available instances for notebooks
- Returns:
- property notebooksmanager: NotebookManager
Manages the run and execution of notebooks
- Returns:
- property runtime_manager: RuntimeManager
Provides information about the available runtimes on the notebook server
- Returns:
- property runtimes: RuntimeManager
Deprecated since version 2.4.2: Removed in: 2.4.5. Use the runtime_manager instead.
Deprecated since version 2.4.2: Removed in: 2.4.5. Use the runtime_manager instead.
- property snapshots: SnapshotManager
Returns tools to work with snapshots on notebooks
- Returns:
ContainerManager
- class arcgis.gis.agonb.ContainerManager(url: str, gis: GIS)
Bases:
objectProvides the ability to manage notebook containers in ArcGIS Online organization.
Parameter
Description
url
Required String. The base url for the ContainerManager endpoints.
gis
Required
GIS. The ArcGIS Online connection object.# Initialize the ContainerManager instance through notebook server manager object from arcgis.gis import GIS gis = GIS(profile="your_online_admin_profile") notebook_manager = gis.notebook_server[0] container_manager = notebook_manager.containers container_manager
- get(id: str) Container
Gets an instance of a container through container id.
Example:
# Usage Example: Get a container by container ID from arcgis.gis import GIS gis = GIS(profile="your_online_admin_profile") notebook_manager = gis.notebook_server[0] container_manager = notebook_manager.containers container = container_manager.get("9bc769b888c8400e9c983846c5a64830") container
Output:
<arcgis.gis.agonb.containers.Container at 0x315f87cb0>
- Returns:
A
Containerobject for the given container ID.
- list(as_dict: bool = True) list[dict[str, Any]] | list[Container]
Returns a list of Container instances or dictionaries representing containers.
Parameter
Description
as_dict
Optional Boolean. If True, returns a list of dictionaries representing containers. If False, returns a list of Container instances. Default is True.
Example:
# Usage Example: Listing notebook containers as default dictionaries from arcgis.gis import GIS gis = GIS(profile="your_online_admin_profile") notebook_manager = gis.notebook_server[0] container_manager = notebook_manager.containers containers = container_manager.list() containers
Output:
[{'id': 'e5d305ec99be480987762e8c1138a486', 'username': 'ArcGISPyAPIBot', 'dateCreated': 1785257430577, 'type': 'openNotebook', 'notebookRuntimeId': 'arcgis-notebook-python-standard:12.1.0.786', 'notebookRuntimeVersion': '14.0', 'notebookRuntimeName': 'ArcGIS Notebook Python 3 Standard', 'numNotebooks': 0}]
Example:
# Usage Example: Listing notebook containers in a list from arcgis.gis import GIS gis = GIS(profile="your_online_admin_profile") notebook_manager = gis.notebook_server[0] container_manager = notebook_manager.containers containers = container_manager.list(as_dict=False) containers
Output:
[<arcgis.gis.agonb.containers.Container at 0x36bcd0180>]
- Returns:
A list of dictionaries with key-value pairs respresenting a
a container, or a list of
Containerinstances. :rtype: list[dict[str, Any]] | list[Container]
- start(runtime: str, instance_type: str | None = None) Future
Starts a container.
Example:
# Usage Example: Start a notebook container with the first available runtime from arcgis.gis import GIS gis = GIS(profile="your_online_admin_profile") notebook_managers = gis.notebook_server notebook_manager = notebook_managers[0] runtime_id = notebook_manager.runtime_manager.list()[0]["id"] container_manager = notebook_manager.containers start_future = container_manager.start(runtime=runtime_id) start_status = start_future.result() start_status
Output:
True- Returns:
A Future for the container start operation. Calling result() returns the result of the start operation.
Container
- class arcgis.gis.agonb.Container(url: str, gis: GIS)
Bases:
objectRepresents a Single Notebook container. Instances of this class are not meant to be intialized directly, but instead are returned by the
get()orlist()methods of theContainerManager.Parameter
Description
url
Required String. The url for the container.
gis
Required GIS. The ArcGIS Online connection object.
Example: Get a Container instance through the ContainerManager.
# Get a Container instance through ContainerManager object from arcgis.gis import GIS from arcgis.gis.agonb.containers import Container gis = GIS(profile="your_online_admin_profile") notebook_manager = gis.notebook_server[0] container_manager = notebook_manager.containers container = container_manager.get("9bc769b888c8400e9c983846c5a64830") container
Output:
<arcgis.gis.agonb.containers.Container at <mem_addr>>
- close(notebook_id: str) bool
Closes a notebook
Example:
# Usage Example: Close a notebook in a container from arcgis.gis import GIS gis = GIS(profile="your_online_admin_profile") notebook_manager = gis.notebook_server[0] container_manager = notebook_manager.containers container = container_manager.get("9bc769b888c8400e9c983846c5a64830") close_status = container.close(notebook_id="9d57910ca80d4211aec1cfe46f2bbea6")
Output:
True- Returns:
True if the notebook was closed successfully, False on a failed async operation, or the raw response when no recognized status payload is returned.
- property notebooks: list[dict[str, Any]]
List all notebooks running in the current container.
Example:
# Usage Example: Get notebooks running in a container from arcgis.gis import GIS gis = GIS(profile="your_online_admin_profile") notebook_manager = gis.notebook_server[0] container_manager = notebook_manager.containers container = container_manager.get("9bc769b888c8400e9c983846c5a64830") notebooks = container.notebooks notebooks
Output:
{'notebooks': [{'id': '9d57910ca80d4211aec1cfe46f2bbea6', 'itemTitle': 'Untitled Notebook', 'dateCreated': 1785181559514, 'dateLastActivity': 1785181559514, 'type': 'openNotebook', 'filename': '05a3a1a4bb2d40b6a53ba90603f9469b.ipynb', 'username': 'ArcGISPyAPIBot', 'containerId': '7991a3e17f7248d19318649b3fe95729'}], 'num': 1}
- Returns:
A dictionary with key as notebooks, whose value is a list of notebook dictionaries.
- property properties
Retrieve the properties of a notebook container.
Example:
# Usage Example: Get container properties from arcgis.gis import GIS gis = GIS(profile="your_online_admin_profile") notebook_manager = gis.notebook_server[0] container_manager = notebook_manager.containers container = container_manager.get("a7fd1047648140aaaad88528fcdd30ad") container_props = container.properties container_props
Output:
{'id': 'a7fd1047648140aaaad88528fcdd30ad', 'username': 'ArcGISPyAPIBot', 'dateCreated': 1784838876254, 'type': 'openNotebook', 'notebookRuntimeId': 'arcgis-notebook-python-standard:12.1.0.786', 'notebookRuntimeVersion': '14.0', 'notebookRuntimeName': 'ArcGIS Notebook Python 3 Standard', 'numNotebooks': 1}
- Returns:
A dictionary containing the properties of the notebook container.
- shutdown() bool
Stops the current container.
Example:
# Usage Example: Shutdown a notebook container from arcgis.gis import GIS gis = GIS(profile="your_online_admin_profile") notebook_manager = gis.notebook_server[0] container_manager = notebook_manager.containers container = container_manager.get("9bc769b888c8400e9c983846c5a64830") shutdown_status = container.shutdown() shutdown_status
Output:
True- Returns:
True if the container was terminated successfully, False if the async operation fails, or the raw response when no recognized status payload is returned.
InstancePreference
- class arcgis.gis.agonb.InstancePreference(url: str, gis: GIS)
Bases:
objectProvides information about the available instances for notebook containers.
Deprecated since version 2.4.4: ArcGIS Online Notebooks no longer supports the underlying
instancePreferencesendpoint. Access throughAGOLNotebookManager.instance_preferencesis deprecated and will be removed in 2.5.0.Parameter
Description
url
Required String. The base url for the InstancePreference endpoints.
gis
Required
GIS. The ArcGIS Online connection object.- property available: dict[T, V]
Returns information on the available notebook instances.
- Returns:
dict[T,V]
- property instances: dict[T, V]
Returns a dictionary containing the available instance types for the system
- Returns:
dict[T,V]
NotebookManager
- class arcgis.gis.agonb.NotebookManager(url, gis, nbs)
Bases:
objectProvides access to managing a site’s notebooks. An object of this class can be created using
notebooksproperty of theNotebookServerclass- execute_notebook(item: Item, update_portal_item: bool = True, parameters: list | None = None, save_parameters: bool = False, instance_type: str | None = None, timeout: float | int = 50, future: bool = False)
The Execute Notebook operation allows administrators to remotely run a notebook in their ArcGIS Notebook Server site. The notebook specified in the operation will be run with all cells in order.
Using this operation, you can schedule the execution of a notebook, either once or with a regular occurrence. This allows you to automate repeating tasks such as data collection and cleaning, content updates, and portal administration. On Linux machines, use a cron job to schedule the executeNotebook operation; on Windows machines, you can use the Task Scheduler app.
Note
To run this operation, you must be logged in with an ArcGIS Enterprise portal account. You cannot execute notebooks from the ArcGIS Notebook Server primary site administrator account.
You can specify parameters to be used in the notebook at execution time. If you’ve specified one or more parameters, they’ll be inserted into the notebook as a new cell. This cell will be placed at the beginning of the notebook, unless you have added the tag parameters to a cell.
Parameter
Description
item
Required
Item. Opens an existing portal item.update_portal_item
Optional Boolean. Specifies whether you want to update the notebook’s portal item after execution. The default is true. You may want to specify true when the notebook you’re executing contains information that needs to be updated, such as a workflow that collects the most recent version of a dataset. It may not be important to update the portal item if the notebook won’t store any new information after executing, such as an administrative notebook that emails reminders to inactive users.
parameters
Optional List. An optional array of parameters to add to the notebook for this execution. The parameters will be inserted as a new cell directly after the cell you have tagged
parameters. Separate parameters with a comma. Use the format “x”:1 when defining parameters with numbers, and “y”:”text” when defining parameters with text strings.save_parameters
Optional Boolean. Specifies whether the notebook parameters cell should be saved in the notebook for future use. The default is false.
instance_type
Optional String. The instance type.
timeout
Optional Int. The number of minutes to run the instance before timeout.
future
Optional boolean. If True, a Job object will be returned and the process will not wait for the task to complete. The default is False, which means wait for results.
- Returns:
Dict, else If
future = True, then the result is a concurrent.futures.Future object. Callresult()to get the response
- open_notebook(itemid: str, templateid: str | None = None, nb_runtimeid: str | None = None, template_nb: str | None = None, instance_type: str | None = None, *, future: bool = False)
Opens a notebook on the notebook server
Parameter
Description
itemid
Required String. Opens an existing portal item.
templateid
Optional String. The id of the portal notebook template. To get the system templates, look at the sample notebooks group:
>>> from arcgis.gis import GIS >>> gis = GIS() >>> grp = gis.groups.search("title:(esri sample notebooks) AND >>> owner:"esri_notebook")[0] >>> grp.content
nb_runtimeid
Optional String. The runtime to use to generate a new notebook.
template_nb
Optional String. The start up template for the notebook.
instance_type
Optional String. The name of the instance type.
future
Optional Bool.
- Returns:
Dict
RuntimeManager
- class arcgis.gis.agonb.RuntimeManager(url: str, gis: GIS)
Bases:
objectClass for retrieving specific
runtimesand information about the *runtimes*in the ArcGIS Online organization.Parameter
Description
url
Required String. The base url for the RuntimeManager endpoints.
gis
Required
GIS. The ArcGIS Online connection object.- property current_runtime_version: str
Retrieves the latest released runtime version.
- list() list[dict[T, V]]
Deprecated since version 2.4.2: Removed in: 2.4.5. Use the RuntimeManager.runtimes instead.
Deprecated since version 2.4.2: Removed in: 2.4.5. Use the RuntimeManager.runtimes instead.
Returns a
listofruntimesin the Online organization.- Returns:
list[dict[T,V]]
- manifest(id: str) dict[T, V]
Deprecated since version 2.4.2: Removed in: 2.4.5. Use the manifest on the AGORuntime class instead.
Deprecated since version 2.4.2: Removed in: 2.4.5. Use the manifest on the AGORuntime class instead.
Returns a
dictionarycontaining all the libraries for the runtime specified by the id parameter.- Returns:
dict[T,V]
- property properties: dict[str, Any]
Provides a Python
dictionarywith key-values pairs representing information about the runtimes resource of the organization.- Returns:
dict[str,Any]
- property runtimes: Iterable[AGORuntime]
Returns all registered
runtimesfor the organization.- Returns:
Iterable[Runtime]
- property session: EsriSession
returns the session object
AGORuntime
- class arcgis.gis.agonb.AGORuntime(url: str, gis: GIS, properties: dict)
Bases:
objectProvides information about the properties of a specific notebook runtime in your ArcGIS organization.
- property manifest
Provides a Python
listofdictionariesof all the Python libraries supported in the specified notebookruntime. Notebook authors who open notebooks using this runtime are able to import any of the libraries in the manifest into their notebooks.- Returns:
Listofdictionarieswith information about about each specific library.
- property session: EsriSession
returns the session object
SnapshotManager
- class arcgis.gis.agonb.SnapshotManager(url: str, gis: GIS)
Bases:
objectAllows for management and creation of
snapshots, which are save points, for ArcGIS Online Notebooks.Objects of this class are not initialized directly. Instead, they are typically accessed through the
snapshotsproperty of theAGOLNotebookManager.from arcgis.gis import GIS gis = GIS("home") ago_nb_mgr = gis.notebook_server[0] snapshot_mgr = ago_nb_mgr.snapshots snapshot_mgr
Output:
<arcgis.gis.agonb.snapshot.SnapshotManager at <mem_addr>>
- create(item: Item, name: str, description: str | None = None, notebook_json: dict | None = None, access: bool = False)
Creates a
SnapShotof the provided notebookItem.Parameter
Description
item
Required
Item. The notebook item to create a asnapshotfor.name
Required String. The name of the snapshot. This is the identifier used to identify the snapshot.
description
Optional String. An piece of text that describes the snapshot.
notebook_json
Optional Dict. If you want to store different JSON text other than what is in the current notebook provide it here.
access
Optional Bool. When false, the snapshot will not be publicly available.
- Returns:
A Python
dictrepresenting the created snapshot.
SnapShot
- class arcgis.gis.agonb.SnapShot(item: Item, sm: SnapshotManager, properties: dict)
Bases:
objectA single save point for a Notebook item.
Objects of this class are not meant to be created directly by users, but instead are retrieved using the
list()method on theSnapshotManager.Example: Retrieving a SnapShot object from a Notebook item
from arcgis.gis import GIS gis = GIS("home") nb_item = gis.content.search( query="City Reports *", item_type="Notebook" )[0] ago_nb_mgr = gis.notebook_server[0] snapshot_mgr = ago_nb_mgr.snapshots snapshots = snapshot_mgr.list(nb_item) snapshot = snapshots[0]
- delete()
Deletes a snapshot associated with the notebook item
Parameter
Description
item
Required Item. The ‘Notebook’ typed item to remove snapshots from.
snapshot
Required String. The name of the snapshot.
- Returns:
A Python
Booleanindicating whether the deletion was successful.
- download()
Saves a snapshot locally on disk as a json file.
- Returns:
A Python
strrepresenting the path of the saved file.
- restore(title: str | None = None, preserve: bool = True, description: str | None = None)
Rolls back the notebook to a previous snapshot state
Note
Only users who own the notebook item can restore snapshots.
Parameter
Description
title
Optional string. The Item’s title.
preserve
Optional Bool. If True, the current notebook version is preserved as a
snapshot.description
Optional String. Text describing the restoration point.
- Returns:
A Python
dictcontaining the status of the operation and a JSON file as a resource.