Skip To Content

Publishing a map service with Python

You can automate map service publishing in a Python script. To do this, you need to call the following sequence of functions from the arcpy.mapping module and tools from the Server toolbox.

  1. Use the arcpy.mapping function CreateMapSDDraft to create a draft service definition (.sddraft). This function reads your map document (MXD) and creates the draft service definition.
    Tip:

    The above-linked topic contains a full code example for publishing a map service using Python.

  2. Use the arcpy.mapping function AnalyzeForSD to analyze your draft service definition for errors that might prevent its publishing. This function returns a Python list of errors, warnings, and informational messages that can help you validate whether your map is ready for publishing. This list is similar to what you get when you click the Analyze button from the Service Editor dialog box in ArcGIS for Desktop.
  3. Run the Stage Service geoprocessing tool on your draft service definition. This converts your draft into a service definition (.sd) that is ready to publish to ArcGIS for Server.
  4. Run the Upload Service Definition geoprocessing tool to publish your service definition as a service.