Select to view content in your preferred language

Connecting to ArcGIS online with arcpy in pycharm

2609
6
02-10-2021 06:47 AM
NikolajKlausen
Emerging Contributor

Dear all,

I am interested in making a python script that reads data from Arcgis Online using ArcPy, but I haven't been able to find much information on the net.

I belong to an organisation that has a ArcGIS Online server.

I am following the udemy course "ArcPy for Python Developers using ArcGIS Pro", but as far as I can tell there is no point where the course covers accessing ArcGIS Online through arcpy.

Is there anyone that might be able to push me in the right direction?

Thank you very much in advance,

Nikolaj

 

 

 

0 Kudos
6 Replies
JoeBorgione
MVP Emeritus

Take a look at the ArcGIS Python API

That should just about do it....
0 Kudos
DanPatterson
MVP Esteemed Contributor
0 Kudos
StuartMoore
Frequent Contributor

you can also use the RestAPI on your feature service to query it, have a look at this:

https://developers.arcgis.com/rest/services-reference/query-feature-service-layer-.htm

i have some python scripts i run using the endpoints and you dont need to have ArcPy installed either just python and i use http requests

Stu

0 Kudos
DavinWalker2
Esri Contributor

Hi Nikolaj,

As mentioned you can connect to ArcGIS Online through the ArcGIS API for Python.

The below is how to establish a connection to ArcGIS online.

from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com", "UserName", "P@ssword123"")

 

zak100
by
New Contributor

@DavinWalker2 Hi,

I am using the above code:

import random
import numpy as np
import sys

from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com", "zak100", "**************")

 

but I am getting the error:

from arcgis.gis import GIS
ModuleNotFoundError: No module named 'arcgis'

 

Somebody please guide me.

Zulfi.

 

0 Kudos
Luke_Pinner
MVP Regular Contributor

@zak100 wrote:

I am using the above code:

import random
import numpy as np
import sys

from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com", "zak100", "**********")

 

but I am getting the error:

from arcgis.gis import GIS
ModuleNotFoundError: No module named 'arcgis'


You need to install arcgis - the ArcGIS API for Python 

@zak100  Note if that is was actually your arcgis.com password (now changed by a mod), I suggest you change it immediately.

0 Kudos