ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

Adding toolboxes in Python

  • Adding and removing server toolboxes

Python is initially only aware of tools stored in ArcGIS system toolboxes like the Data Management Tools, Conversion Tools, and Analysis Tools toolboxes. Custom tools created by an individual, third party, or organization and stored in a custom toolbox can be accessed in the Python window like any system tool by importing the custom toolbox into the ArcPy site package.

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

>>> arcpy.ImportToolbox("c:/mytools/geometrytools.tbx")
>>> 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 execute 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.tbx", "mytools")
>>> arcpy.CreateRegularPolygons_mytools(

Adding and removing 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.

Sample syntax for adding a geoprocessing service

# Import a geoprocessing service
#
import arcpy

# To add a toolbox from a Internet server, provide the url and toolbox name 
#   delimited by a semi-colon
#
arcpy.ImportToolbox("http://lab13/arcgis/services;BufferByVal")

Sample syntax for adding a local geoprocessing service

# Import a local geoprocessing service
#
import arcpy

# To add a toolbox from a local server, provide the server and toolbox name 
#   delimited by a semi-colon
#
arcpy.ImportToolbox("lab13;BufferByVal")

Related topics

  • ImportToolbox
  • Creating a toolbox
  • Renaming a toolbox: name, label, and alias

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2019 Esri. | Privacy | Legal