[Twisted-Python] Utilizing Twisted for transport w/ SUDS

jathan. jathan at gmail.com
Mon Apr 19 19:26:56 EDT 2010


I have a project that is based on Twisted used to
communicate with network devices and I am adding support for a new
vendor (Citrix NetScaler) whose API is SOAP.  Unfortunately the
support for SOAP in Twisted still relies on SOAPpy, which is badly out
of date. In fact as of this email (I just checked), twisted.web.soap
itself hasn't even been updated in 21 months!

I would like to ask if anyone has any experience they would be willing
to share with utilizing Twisted's superb asynchronous transport
functionality with SUDS.  It seems like plugging in a custom Twisted
transport would be a natural fit in SUDS' Client.options.transport, I'm just
a hard time wrapping my head around it.

I did come up with a way to call the SOAP method with SUDS
asynchronously by utilizing twisted.internet.threads.deferToThread(),
but this feels like a hack to me.

Here is an example of what I've done, just to give you an idea:

   # netscaler is a module I wrote using suds to interface with NetScaler
   # Source: http://bitbucket.org/jathanism/netscaler-api/src
   import netscaler
   import os, sys
   from twisted.internet import reactor, defer, threads

   # netscaler.API is the class that sets up the suds.client.Client object
   host = 'netscaler.local'
   username = password = 'nsroot'
   wsdl_url = 'file://' + os.path.join(os.getcwd(), 'NSUserAdmin.wsdl')
   api = netscaler.API(host, username=username, password=password,

   results = []
   errors = []

   def handleResult(result):
       print '\tgot result: %s' % (result,)

   def handleError(err):
       sys.stderr.write('\tgot failure: %s' % (err,))

   # this converts the api.login() call to a Twisted thread.
   # api.login() is equivalent to:
   # api.service.login(username=self.username, password=self.password)
   deferred = threads.deferToThread(api.login)
   deferred.addCallbacks(handleResult, handleError)


This works as expected and defers return of the api.login() call until
it is complete, instead of blocking.  But as I said, it doesn't feel

Thanks in advance for any help, guidance, feedback, criticism,
insults, or total solutions.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20100419/81ce6ffd/attachment.htm 

More information about the Twisted-Python mailing list