Accessing licenses and extensions in Python

Whenever a tool is executed in a script, an ArcGIS license is required. Tools from ArcGIS extensions, such as the ArcGIS Spatial Analyst extension, require an additional license for that extension. If the necessary licenses are not available, a tool fails and returns error messages. For example, if you install with an ArcGIS for Desktop Basic license, and you attempt to execute a tool that requires a Standard or Advanced license, the tool will fail.

When using an ArcGIS for Desktop Basic or Standard license, a script should set the product to Basic or Standard. Likewise, when using an Engine or EngineGeoDB license, a script should set the product to Engine or EngineGeoDB. If a license is not explicitly set, the license will be initialized based on the highest available license level the first time an ArcPy tool, function, or class is accessed.

Every tool checks to ensure it has the appropriate license. If it doesn't have what's required, it fails. To guard against the situation of executing partially through and failing, you can perform a check at the top of your script and fail immediately.

TipTip:

The setting of the product and extensions is only necessary within stand-alone scripts. If you are running tools from the Python window or using script tools, the product is already set from within the application, and the active extensions are based on the Extensions dialog box.

Desktop, Engine/Server licenses

Product modules are imported prior to the import of arcpy to define the desktop license used by a script. The CheckProduct function can be used to check the availability of desktop licenses, while the ProductInfo function reports what the current product license is.

LegacyLegacy:

The product level should be set by importing the appropriate product module (arcinfo, arceditor, arcview, arcserver, arcenginegeodb, or arcengine) prior to importing arcpy. The SetProduct function is a legacy function and cannot set the product once arcpy has been imported.

Extension licenses

Licenses for extensions can be retrieved from a license manager and returned once they are no longer needed. CheckExtension is used to see if a license is available to be checked out for a specific type of extension, while CheckOutExtension actually retrieves the license. Once the extension license has been retrieved by the script, extension tools can be executed. Once a script is done using tools from a particular extension, the CheckInExtension function should be used to return the license to the license manager so other applications can use it. All checked-out extension licenses and set product licenses are returned to the license manager when a script completes.

The following example executes some ArcGIS 3D Analyst tools and sets the desktop product license to ArcGIS for Desktop Basic, since an ArcGIS for Desktop Advanced license is not required to execute tools from an extension. The script will fail if the ArcGIS for Desktop Basic license is not explicitly set and no ArcGIS for Desktop Advanced license is available, since a desktop license is required to execute extension tools.

class LicenseError(Exception):
    pass

# Set desktop license used to ArcGIS for Desktop Basic
#
import arcview
import arcpy
from arcpy import env

try:
    if arcpy.CheckExtension("3D") == "Available":
        arcpy.CheckOutExtension("3D")
    else:
        # Raise a custom exception
        #
        raise LicenseError
    
    env.workspace = "D:/GrosMorne"
    arcpy.HillShade_3d("WesternBrook", "westbrook_hill", 300)
    arcpy.Aspect_3d("WesternBrook", "westbrook_aspect")

except LicenseError:
    print "3D Analyst license is unavailable"  
except:
    print arcpy.GetMessages(2)
finally:
    # Check in the ArcGIS 3D Analyst extension
    #
    arcpy.CheckInExtension("3D")

In the above example, the ArcGIS 3D Analyst extension is checked in under a finally clause, ensuring that the extension is always checked back in, whether an exception has occurred or not.

A returned value of Failed, Unavailable, or NotLicensed indicates that the extension could not be successfully checked out.

Below are the extension names and their extension code names:

Extension

Extension Code

ArcGIS 3D Analyst extension

3D

ArcGIS Data Interoperability extension for Desktop

DataInteroperability

ArcGIS Data Reviewer for Desktop

Datareviewer

ArcGIS for Aviation: Airports

Airports

ArcGIS for Aviation: Charting

Aeronautical

ArcGIS for Maritime: Bathymetry

Bathymetry

ArcGIS for Maritime: Charting

Nautical

ArcGIS Geostatistical Analyst extension

GeoStats

ArcGIS Network Analyst extension

Network

ArcGIS Spatial Analyst extension

Spatial

ArcGIS Schematics extension

Schematics

ArcGIS Tracking Analyst extension

Tracking

ArcGIS Workflow Manager for Desktop

JTX

ArcScan

ArcScan

Business Analyst

Business

Esri Defense Mapping

Defense

Esri Production Mapping

Foundation

Esri Roads and Highways

Highways

StreetMap

StreetMap

Product code names

Product Codes

ArcView (equivalent to ArcGIS for Desktop Basic license)

ArcEditor (equivalent to ArcGIS for Desktop Standard license)

ArcInfo (equivalent to ArcGIS for Desktop Advanced license)

Engine

EngineGeoDB

ArcServer

Licensing functions

Function

Explanation

CheckExtension(extension)

Checks to see if a license is available to be checked out for a specific type of extension.

Return Value

Meaning

Available

The requested license is available to be set.

Unavailable

The requested license is unavailable to be set.

NotLicensed

The requested license is not valid.

Failed

A system failure occurred during the request.

CheckInExtension(extension)

Returns the license so other applications can use it.

Return Value

Meaning

NotInitialized

No desktop license has been set.

Failed

A system failure occurred during the request.

CheckedIn

The license has been returned successfully.

CheckOutExtension(extension)

Retrieves the license.

Return Value

Meaning

NotInitialized

No desktop license has been set.

Unavailable

The requested license is unavailable to be set.

CheckedOut

Successfully set the license.

CheckProduct(code)

Checks to see if the requested license is available.

Return Value

Meaning

AlreadyInitialized

License has already been set in the script.

Available

The requested license is available to be set.

Unavailable

The requested license is unavailable to be set.

NotLicensed

The requested license is not valid.

Failed

A system failure occurred during the request.

ProductInfo()

Returns the current product license.

Return Value

Meaning

NotInitialized

No license has been set.

ArcInfo

An ArcGIS for Desktop Advanced license has been set.

ArcEditor

An ArcGIS for Desktop Standard license has been set.

ArcView

An ArcGIS for Desktop Basic license has been set.

ArcServer

An ArcGIS for Server license has been set.

EngineGeoDB

An EngineGeoDB license has been set.

Engine

An Engine license has been set.

SetProduct(code)

Defines the desktop license.

Return Value

Meaning

CheckedOut

Successfully set the license.

AlreadyInitialized

License has already been set in the script.

NotLicensed

The requested license is not valid.

Failed

A system failure occurred during the request.

3/3/2014