I'm developing some code that I want to run both as an ArcGIS Server web service and as a standalone script. I want to be able to modify the execution slightly depending on whether it's running as an AGS web service or as a standalone python/within Desktop.

Is there a way to detect this?

I've done some searching but haven't found anything very satisfactory. I have seen arcpy.mapping.CreateGISServerConnectionFile, but this sets connections to a server as opposed to checking the current environment. I've also looked for information on how services are run w/in AGS (e.g., this), but I'm not really seeing anything along the lines of an arcpy.isWebService() type of function. Do I just need to check the environment (like to see if "%scratchFolder% has been set or examining something related to sys.argv)? Seems kind of an unstable solution.


3 Answers 3


@KHibma and others made me wonder if I might get the information by using arcpy to check the version. I dug around somewhat blindly and I think I've got something even if it's not what I was expecting. I haven't checked under AGS yet.

It produces a nice dict:

>>> d=arcpy.GetInstallInfo()
>>> d

{'BuildNumber': u'2414',
 'InstallDate': u'5/16/2012',
 'InstallDir': u'C:\\ArcGIS\\Desktop10.0\\',
 'InstallTime': u'16:32:14',
 'InstallType': u'N/A',
 'Installer': u'abock',
 'ProductName': u'desktop',
 'SPBuild': u'',
 'SPNumber': u'4',
 'SourceDir': u'\\\\igskahhwvsawesm\\arcgis_10\\Desktop\\Desktop\\',
 'Version': u'10.0'}

So I can say:

if d['ProductName'] == u'desktop':

Thanks for kicking that around!

  • Just noticed this comes back as "Desktop" in 10.1, so better locase that if statement to use d['ProductName'].lower().
    – Roland
    Jun 4, 2013 at 20:13
  • Can you post what the result is on Server? Could be useful for future reference.
    – Petr Krebs
    Jun 4, 2013 at 20:18
  • Definitely. Sorry for the delay. Had to go through my colleague who runs the AGS installation. Under 10.1, he got "Server". We don't have a 10.0 AGS instance, but running the result through some kind of capitalization function is probably a good idea.
    – Roland
    Jun 4, 2013 at 21:15
  • I forgot about arcpy.GetInstallInfo(). While it's purpose isn't to tell you what you're running under (it acts much the same as ListInstallations ... I believe it only returns engine|desktop when run from 32 and server when run from 64bit Python. But if you're back at 10.0 like it shows in your message, you'll have both server and desktop to decide upon
    – KHibma
    Jun 4, 2013 at 21:22
  • 2
    @Roland so I tested a couple more things after talking to a colleague. I dont have 10.0 with DT/AGS on the same machien, so I dont know how this will go, but try "arcpy.ProductInfo()". It tells you ArcINFO or ArcSERVER ... this actually might do it for you IF you're either running on DT, or the script as a GP Service in BOTH 10.0 and 10.1
    – KHibma
    Jun 4, 2013 at 22:10

I suggested this, after looking over the results of sys.executable, arcpy.GetInstallInfo(), ListInstallations(), and ProductInfo(), none of which gave me good answer as to which arcpy I was running. @KHibma, something for the arcpy team to think about - it would be a nice property (arcpy.version -- like sys.version) to have.

>>> import arcpy
>>> arcpy.__file__

I cast this test as a function. If you need to know the Python bits, I think it's best to just test sys.version for containing "32 bit" so I didn't include that. Digging out the ArcGIS version is a bit more code so I went ahead and included that in the function.

# report arcpy platform and version
# author: Curtis Price, [email protected]
# date: 2014/08/09 (update to support ArcGIS Pro)

def ArcPyVersion():
    """Report ArcPy version


    >>> ArcPyVersion()
    'Desktop 10.1.3143'
    import arcpy
    f = arcpy.__file__
    if f.find("Desktop") > 0:
      v = "Desktop" 
    elif f.lower().find("arcgis pro") > 0:
      v = "ArcGISPro"
      v = "Server"
    i = arcpy.GetInstallInfo()
    v = "{0} {1}.{2}".format(
            v, i["Version"], i["BuildNumber"])
    return v 
  • 1
    So it seems like arcpy.__file__, arcpy.GetInstallInfo(), and arcpy.ProductInfo() will all yield similar information (even if one produces "Desktop" while the other produces "ArcInfo"). I'm thinking the arcpy.ProductInfo() option is the most concise and readable option.
    – Roland
    Jun 4, 2013 at 23:20
  • Haven't tested it but productinfo may give you the highest available license level if you haven't specifically imported it with "import arceditor" for example). Meaning if you only have ArcEditor available, that's what you'll probably get back. Funny that Server doesn't do the same thing, since it also supports multiple license levels (basic, standard, enterprise) Jun 5, 2013 at 0:14
  • Should be noted that this Python code assumes the software is installed using the normal folder naming conventions. It is pretty rare for someone not to use the default folder name "Desktop10.1" evn if they may move the path around (for example, we install to "C:\ArcGIS\Desktop10.1". Aug 9, 2014 at 19:28
[u'desktop', u'engine', u'server']

So you can do a check of whats installed. This however wont get you very far if both DT and Server are installed on the same machine. As for a function that tells you what you're running under, no, doesnt exist.

Thinking out loud: DT is 32bit, Server is 64bit. You could do a sys.path and inspect which version of Python is being used.


If you know its either running as a GP Service (not just using server's python) vs DT, you could inspect the path of arcpy.env.scratchFolder. On a typical install it'll always look something like C:\arcgisserver\directories\arcgisjobs\[service]_gpserver\[guid]\....

  • And don't forget that ArcGIS Desktop 10.1 has an option to install 64-bit background geoprocessing which installs Python 64-bit.
    – MLowry
    Jun 4, 2013 at 19:41
  • Wouldn't this method to call ArcObjects from python allow you to call RuntimeManager.ActiveRuntime? Jun 4, 2013 at 19:48
  • 2
    RuntimeManager is .NET, not a COM object.
    – Petr Krebs
    Jun 4, 2013 at 20:07
  • C:\Program Files (x86)\Common Files\ArcGIS\bin\ArcGISVersion.dll is a loadable type library that has many of the same objects, you could use that from comtypes. Jun 4, 2013 at 22:21

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.