The SignInToPortal function allows you to sign in to a portal.
To share content or run Ready To Use Tools, you must be signed into a portal. Your portal can be either ArcGIS Enterprise or ArcGIS Online.
Portal connections can still be added by clicking the Project tab on the ribbon and clicking the Portals page
SignInToPortal will add the portal URL to your portal connections, if not already included, sign in, and set the portal to active. If executed in the Python window, the portal will be set as the active portal, if different, and add it to the portal connections for future ArcGIS Pro or stand-alone Python sessions. However, if executed in a stand-alone Python session, the portal information is used only for the duration of the active Python session.
Portals that use Integrated Windows Authentication are not supported; username and password are required parameters.
SignInToPortal (portal_url, username, password)
The URL of the portal to be signed in to.
The user name of the user signing in to the portal.
The password of the user signing in to the portal.
A dictionary of key value pairs for expires, referer, and token.
import arcpy arcpy.SignInToPortal(arcpy.GetActivePortal(), 'username', 'password')