HOW TO
In ArcGIS API for Python, the Jupyter Notebook can be used to visualize real-time data. This is possible using the arcgis.realtime Python module. Within the module, use the subscribe() method with the prerequisite packages installed on the machine.
To use the subscribe() method, the following packages are required:
The packages can be installed using the Python Command Prompt. Run the following command to install the selected packages individually.
conda install <package name>
Note: Some of the packages may have been installed during the ArcGIS API for Python installation. To check the installed packages, refer to ArcGIS Pro: Python Package Manager.
The following steps demonstrate how to subscribe to stream services:
from arcgis import GIS from arcgis.realtime import StreamLayer import ssl, json
ssl._create_default_https_context = ssl._create_unverified_context url = "https://geoeventsample1.esri.com:6443/arcgis/rest/services/AirportTraffics/StreamServer" streamLayer = StreamLayer(url)
def callback(event): event_as_json = json.loads(event) print(event_as_json)
streamLayer.subscribe(callback)The following is a sample of the full script:
from arcgis import GIS from arcgis.realtime import StreamLayer import ssl, json ssl._create_default_https_context = ssl._create_unverified_context url = "https://geoeventsample1.esri.com:6443/arcgis/rest/services/AirportTraffics/StreamServer" streamLayer = StreamLayer(url) def callback(event): event_as_json = json.loads(event) print(event_as_json) streamLayer.subscribe(callback)
Note: The code may not run as expected in a Jupyter Notebook if it is terminated midway. If this happens, restart the notebook kernel and rerun the code.
Get help from ArcGIS experts
Download the Esri Support App