Skip to main content

Add toolboxes in Python

ArcPy is initially only aware of tools stored in ArcGIS system toolboxes. Custom tools created by an individual, third party, or organization and stored in a custom toolbox can be accessed in ArcPy like any system tool by importing the custom toolbox.

In the following example, the ImportToolbox function is used to allow tools contained in a custom toolbox to be accessed in ArcPy. After importing the toolbox, the custom tools can be accessed as arcpy.<toolname>_<alias>.

>>> arcpy.ImportToolbox("c:/mytools/geometrytools.atbx")
>>> arcpy.CreateRegularPolygons_geometry(

When a tool is accessed through the ArcPy site package, the toolbox alias where the tool is contained is a required suffix (arcpy.<toolname>_<alias>). Since ArcPy depends on toolbox aliases to access and run the correct tool, aliases are extremely important when importing custom toolboxes. A good practice is to always define a custom toolbox's alias. However, if the toolbox alias is not defined, a temporary alias can be set as the second parameter of the ImportToolbox function.

>>> arcpy.ImportToolbox("c:/mytools/geometrytools.atbx", "mytools")
>>> arcpy.CreateRegularPolygons_mytools(

Server toolboxes

Geoprocessing services can also be added to the scripting environment using ImportToolbox. Whether adding the geoprocessing service from a local or internet server, the server and toolbox name are semicolon delimited.

To add a toolbox from a Internet server, provide the url and toolbox name delimited by a semi-colon.

import arcpy

arcpy.ImportToolbox("http://lab13/arcgis/services;BufferByVal")

To add a toolbox from a local server, provide the server and toolbox name delimited by a semi-colon.

import arcpy

arcpy.ImportToolbox("lab13;BufferByVal")