A Python toolbox (.pyt file) is a simple text file that can be created, viewed, and edited in any text editor such as Microsoft Notepad or VI, or any Python integrated development environment (IDE).
The toolbox is created as a class named Toolbox. In the Toolbox class's __init__ method, properties of the toolbox are defined, including the alias, label, and description. The name of the toolbox is defined by the name of the .pyt file. The tools property must be set to a list containing all tool classes defined in the toolbox.
Tip:
To ensure that the Python toolbox is recognized correctly, the toolbox class name must remain Toolbox.
By default, the Python toolbox template creates a stubbed-out tool named Tool. The template code used to create the Python toolbox is shown in the Python toolbox template topic.
Note:
When you interact with a Python toolbox in ArcGIS Pro, the toolbox code loads. When loading the toolbox for the first time or when ArcGIS Pro detects a change in the code, the application prompts you to confirm whether you trust the code source. You can then grant or deny permission to load the toolbox.
ArcGIS Pro immediately runs any code at the top level—outside of a function or method—when it loads the toolbox. This can result in unexpected behavior. Additionally, some ArcPy functions may not work as expected when called at the top level.
To prevent unintended behavior, encapsulate your code within function or method blocks.
To create a Python toolbox, complete the following steps:
- In the Catalog pane, click Toolboxes.
- Click New .
- Browse to the folder where you want to save the Python toolbox, provide a name in the Name text box, and click Save.