Listing tools, toolboxes, and environment settings

Depending on which toolboxes are available, ArcPy might have access to several toolboxes, dozens of environment settings, and hundreds of tools. ArcPy has several appropriately named functions to return a list of tools (ListTools), environment settings (ListEnvironments), or toolboxes (ListToolboxes).

Each function has a wild card option and returns a list of name strings that can be looped through. The example below shows how to access available tools and print out their usage.

import arcpy

# Create a list of the conversion tools
tools = arcpy.ListTools("*_conversion")

# Loop through the list and print each tool's usage
for tool in tools:
    print(arcpy.Usage(tool))

The following sample provides an approach for viewing environment settings in Python.

import arcpy

environments = arcpy.ListEnvironments()

# Sort the environment list, disregarding capitalization
environments.sort(key=str.lower)

for environment in environments:
    # As the environment is passed as a variable, use Python's getattr to 
    # evaluate the environment's value
    env_value = getattr(arcpy.env, environment)

    # Format and print each environment and its current setting
    print("{0:<30}: {1}".format(environment, env_value))

The following sample provides an approach for viewing current toolboxes in Python.

import arcpy 

# Print all current toolboxes
for toolbox in arcpy.ListToolboxes():
    # Toolboxes are printed in the form of "toolbox_name(toolbox_alias)"
    print(toolbox)