For one of my tasks I need to create a Toolbox with three tools (python scripts).

Instead of ordinary tbx I've decided to write it as Python Toolbox (pyt).

Everything is clear except the "good" way to organize the code.

As I have three tools it is not good way to store them in one file (pyt). So, I've decided to keep each tool in a separate .py file.

Here is a problem: what is the good way to organize several files with PYT for distribution or deployment on ArcGIS for Server? Should I keep them on the same level with PYT file or should I place them in some subdirectory (i.e. "Tools")?

Can you recommend any Esri guidelines or reference "big PYT toolbox" sample?

I have not find anything on this topic. In version 10.0 there was so called ToolShare folder structure which I've used.

This is more a question of style of coding. Because the idea to create one PYT file with 500-1000 or more lines of code does not look good to me and I believe it is not "pythonic" way.

  • 3
    "the idea to create one PYT file with 500-1000 or more lines of code does not look good to me". U're not alone, Alex. Today I promptly stated that .pyt is an invention of sick mind. And I won't regret it. Commented Mar 7, 2014 at 22:04

1 Answer 1


Have a look at this thread on the ArcGIS forum. Basically just use standard python modules or a package structure and import your tools into the python toolbox.

Something like:

#  \--SomeDir
#     |  toolbox.pyt
#     \--toolpackage
#        |  __init__.py
#        |  script_a.py
#        |  script_b.py

#The .pyt file

import arcpy
import toolpackage.script_a.Tool1 as Tool1
import toolpackage.script_a.Tool2 as Tool2
import toolpackage.script_b.Tool3 as Tool3

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "MultiTool Toolbox"
        self.alias = "mtt"

        # List of tool classes associated with this toolbox
        self.tools = [Tool1, Tool2, Tool3]
  • I've found that this works ok in ArcGIS Desktop, but when publishing a geoprocessing service to an ArcGIS Server instance then it loses all of the scripts and packages, apart from the .pyt file. It might be possible to drop the scripts into the deployment manually, but that increases complexity.
    – Gnat
    Commented Jun 20, 2013 at 6:42
  • 4
    @Gnat Yes, Luke's thoughts are my experience as well. ESRI's publishing services don't recognize any of the from x import y style imports. (That is entirely ridiculous, by the way.) However, I believe you can leave your self.tools definition alone and use import toolpackage.script_a.Tool1 as Tool1.
    – jpmc26
    Commented Feb 25, 2014 at 13:58
  • 1
    The alias should be short and only contain letters, i.e. self.alias = "mtt" Commented Nov 26, 2015 at 9:00
  • 4
    Since I just spent an hour making changes to my tools code and trying to seem it reflected in the tool gui in Arcmap I would like to share this. If you make changes in your code outside of the pyt file and would like to see it reflected in the tool gui you have to restart ArcMap/Catalog. You can hit refresh on the toolbox all you want, that only seems to reload the pyt itself. It wont find the changes to the other code.
    – TurboGus
    Commented Jun 16, 2016 at 22:22
  • 1
    @TurboGus gis.stackexchange.com/q/91112/2856
    – user2856
    Commented Jun 16, 2016 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.