Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
"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. – r.pankevicius Mar 7 '14 at 22:04
up vote 12 down vote accepted

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
#        |
#        |
#        |

#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 = [Tool1, Tool2, Tool3]
share|improve this answer
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 Jun 20 '13 at 6:42
@Gnat - see the "Importing other Python modules" section in the ArcGIS Server help. Maybe the from toolpackage.script_a import Tool1 needs to be replaced with import toolpackage.script_a and[toolpackage.script_a.Tool1, etc...] – Luke Jun 25 '13 at 21:45
@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 definition alone and use import toolpackage.script_a.Tool1 as Tool1. – jpmc26 Feb 25 '14 at 13:58
The alias should be short and only contain letters, i.e. self.alias = "mtt" – Curtis Price Nov 26 '15 at 9:00
@CurtisPrice Thanks for pointing the issue out. Back when I wrote this post I was still using 10.0 so couldn't test. – Luke Nov 26 '15 at 22:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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