Here's the end result I'm trying for:

  • the user clicks on a feature on an ArcGIS Server JS map
  • a Python script is triggered on the server
  • the Python script uses an attribute from the feature (eg its OID) to perform some calculations (using arcpy modules)
  • the results are returned to the infoWindow as HTML, for display

I guess I'd need to be able to trigger a Python script (containing arcpy commands) on the server, passing parameters between the client and server.

Assuming this is possible, what is the best approach:

  • via the ArcGIS Server geoprocessing framework
  • directly via an AJAX call to the Python script (and is that even possible)?
  • something else?
  • Have you had a look at this response: stackoverflow.com/questions/2201561/…? It seems to be doing what you are asking. Mar 3, 2015 at 20:18
  • Thanks @Mr.Concolato - good to know. Since I'm relying on arcpy functionality, the AJAX approach probably requires a dedicated installation of ArcGIS Desktop on the server(?) so the geoprocessing service approach may be more suitable? Mar 4, 2015 at 21:42

3 Answers 3


This is the precise use case for a geoprocessing service. Write your script and add it to a geoprocessing toolbox on the server as a script tool.

You can test it on the server while developing the script by hard coding the parameters. Once you're comfortable with your code, replace those hard coded parameters with arcpy.GetParameterAsText(), add to a geoprocessing toolbox as a script tool and publish to ArcGIS Server as either a synchronous (Execute Task) or asynchronous (Submit Job) service.

You can then use the geoprocessor (https://developers.arcgis.com/javascript/jshelp/intro_gp_overview.html) in the Javascript api to send a request to the service as well as handle the result.

  • Thanks Jeremy. I'm experienced in Python scripts on the client, but a total novice at using them via ArcGIS Server, so I'll give this a try Mar 2, 2015 at 0:57
  • Sure thing, feel free to let me know if you have any issues. I'm quite certain that you won't have many issues getting it working and published. For a python developer, the more challenging part is going to be writing the Javascript code to call the service and handle the result. Mar 2, 2015 at 1:31
  • What is a geoprocessing service states a task takes simple data captured in a web application, processes it, and returns meaningful and useful output in the form of features, maps, reports, and files - but what if I want to return text, in the form of HTML? Mar 2, 2015 at 3:11

Having trouble adding a comment from my phone, so posting here...

I would recommend that you become familiar with JSON, if not already. I would develop your service to return a JSON object that contains key/value pairs that hold the results of your calculation. That JSON object can be easily parsed in your javascript, placed into existing html or used to create new html which can be displayed in your infoWindow.

  • This is probably veering towards needing a new question, but I'll persist here for the moment. Assuming I've built up a JSON object in Python - what is the command to return the JSON object from the server to the client? thanks Mar 2, 2015 at 4:34
  • 1
    arcpy.SetParameterAsText(json.dumps(<pythonDict>)) Mar 3, 2015 at 1:14
  • ... still working on it but gis.stackexchange.com/a/34968/3112 helps - I need to set a Derived output parameter in order to receive a response back from the script. Mar 6, 2015 at 0:00
  • Sorry I'm not getting emails when you comment, feel free to pm me (if possible) and I'll be happy to share how we normally do this Mar 12, 2015 at 22:35

You can run python Script by using "python Shell" package https://github.com/extrabacon/python-shell

  • 1
    I don't think this really answers the question. How should the OP use "python Shell" with his configuration to run his ArcPy Python scripts
    – nmtoken
    Sep 30, 2019 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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