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

Landreville landreville at deadtreepages.com
Tue Apr 20 09:34:44 EDT 2010

On Mon, Apr 19, 2010 at 7:26 PM, jathan. <jathan at gmail.com> wrote:
> Hello-
> 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
> having
> 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.

I did a similar thing. I wrapped the SUDS client calls into
deferToThread by subclassing suds.Client and adding a method
callMethod which returns a deferred. Here is the code I'm using:
""" Wrapper for suds to create deferred instances. """
from suds.client import Client as SudsClient
from twisted.internet.threads import deferToThread

class Client(SudsClient):

    # method for returning a deferred for the RPC
    def callRemote(self, method, *args, **kwargs):
        def call(m, *a, **kw):
            result = self.service.__getattr__(m)(*a, **kw)
            return result
        d = deferToThread(call, method, *args, **kwargs)
        return d

More information about the Twisted-Python mailing list