The ArcGIS API for Python is a powerful Python package that can be used to manage, control and explore spatial data. It combines the best of data science with the power to manage your GIS infrastructure. The package is lightweight and nimble and allows users from all levels of GIS backgrounds to quickly map information, manage GIS infrastructure (servers, portals, etc.) and start understanding quickly.
I am going to assume the packagae has been installed. If you need help doing that step, please refer to https://developers.arcgis.com/python/guide/install-and-set-up/
In Python, librraries are loaded/accessed using the import statement as such:
Python also allows developers to access a part or parts of a library to let users only load what they need. This is done using the from < x > import < y >
from arcgis.gis import GIS
Here we just loaded the GIS class from the arcgis.gis module.
Now that we have what we need to login to our GIS, we can login or access a site anonymously.
The first example is showing how to login to Portal for ArcGIS (this code won't work unless you replace the values):
gis = GIS(url="http://mysite.com/portal", username="useraccount", password="secret")
To access ArcGIS Online, you do not have to provide a url because it it the default site. Here you can specify the username and password for a non-anonymous connection, else you can just provide credentials to login to your organization.
gis = GIS()
gis = GIS(username='myaccount', password='fake password')