I need to list out data sources for some portal items using ArcGIS api for python, then get information for those data sources that only arcpy can provide.
Can arcpy be used in an ArcGIS api for python script?
I could make an arcpy script and use ArcGIS Rest API within it, but I'd like to leverage the new ArcGIS API for python if possible.
Thank you,
Randy McGregor
Solved! Go to Solution.
Thank you! I'm a bit embarrassed that it is that straightforward. I did have the impression that you couldn't directly access arcpy in this manner, but I was mistaken about that, apparently.
import arcpy
start a Jupyter Notebook or JupyterLab notebook run the import arcpy. You have access to arcpy and the tools in arctoolbox as well
Thank you! I'm a bit embarrassed that it is that straightforward. I did have the impression that you couldn't directly access arcpy in this manner, but I was mistaken about that, apparently.
Yes they can be used together. However, you need to use python 3 so you need to install pro.
Thanks. I do have pro installed.
Its as simple as import arcpy, arcgis (if you arent using notebooks)
So, if you're just making a "regular" python script with IDLE, import both arcpy and arcgis, then you have the both arcpy and arcgis api for python libraries?
Yes. That is exactly what I do!
I would suggest not, unless you need both arcpy and arcgis. Loading unnecessary modules into an IDE or script should be avoided for both performance and maintainability reasons. That said, arcgis loads arcpy for its own internal uses if arcpy is available, which is partially why loading arcgis takes so long relative to other packages.
>>> import sys
>>> sys.modules.keys() & {'arcpy', 'arcgis'}
set()
>>> import arcgis
>>> sys.modules.keys() & {'arcpy', 'arcgis'}
{'arcgis', 'arcpy'}
>>>
I haven't had any real problems with it.