The following code will publish a hosted feature service. Change the following:- Line 5, the workspace- Line 11, the name you want to give the service- Line 58, the username and password to your AGO accountimport arcpy import xml.dom.minidom as DOM import os workspace = 'C:/Temp/hosted publishing/' # Reference map document for CreateSDDraft function. mapDoc = arcpy.mapping.MapDocument(r'C:\Temp\betty4.mxd') # Create service and sddraft variables for CreateSDDraft function. sddraft = workspace + 'HostedMS.sddraft' service = 'FeatureService' arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'MY_HOSTED_SERVICES', summary="test", tags='test') con = 'My Hosted Services' sd = workspace + service + '.sd' doc = DOM.parse(sddraft) # Read the sddraft xml. doc = DOM.parse(sddraft) # Change service from map service to feature service typeNames = doc.getElementsByTagName('TypeName') for typeName in typeNames: # Get the TypeName we want to disable. if typeName.firstChild.data == "MapServer": typeName.firstChild.data = "FeatureServer" #Turn off caching configProps = doc.getElementsByTagName('ConfigurationProperties')[0] propArray = configProps.firstChild propSets = propArray.childNodes for propSet in propSets: keyValues = propSet.childNodes for keyValue in keyValues: if keyValue.tagName == 'Key': if keyValue.firstChild.data == "isCached": # turn on caching keyValue.nextSibling.firstChild.data = "false" #Turn on feature access capabilities configProps = doc.getElementsByTagName('Info')[0] propArray = configProps.firstChild propSets = propArray.childNodes for propSet in propSets: keyValues = propSet.childNodes for keyValue in keyValues: if keyValue.tagName == 'Key': if keyValue.firstChild.data == "WebCapabilities": # turn on caching keyValue.nextSibling.firstChild.data = "Query,Create,Update,Delete,Uploads,Editing" outXml = workspace + 'HostedMSNew.sddraft' f = open(outXml, 'w') doc.writexml( f ) f.close() analysis = arcpy.mapping.AnalyzeForSD(outXml) #print analysis #arcpy.SignOutFromPortal_server() arcpy.SignInToPortal_server("username","password","http://www.arcgis.com/") arcpy.StageService_server(outXml, sd) arcpy.UploadServiceDefinition_server(sd, con)