Can arcpy and ArcGIS API for Python code be used together?

1055
9
Jump to solution
01-07-2020 05:45 AM
by Anonymous User
Not applicable

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?

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

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

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.

View solution in original post

0 Kudos
9 Replies
DanPatterson_Retired
MVP Esteemed Contributor

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

by Anonymous User
Not applicable

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.

0 Kudos
PatrickFilyer
Occasional Contributor II

Yes they can be used together. However, you need to use python 3 so you need to install pro. 

by Anonymous User
Not applicable

Thanks. I do have pro installed.

PatrickFilyer
Occasional Contributor II

Its as simple as import arcpy, arcgis (if you arent using notebooks)

0 Kudos
by Anonymous User
Not applicable

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?

PatrickFilyer
Occasional Contributor II

Yes. That is exactly what I do! 

JoshuaBixby
MVP Esteemed Contributor

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'}
>>> 
0 Kudos
PatrickFilyer
Occasional Contributor II

I haven't had any real problems with it. 

0 Kudos