Is it possible to cache the pudon suds client?

I am currently running python suds against a wsdl file and its corresponding 50+ xsd files. The following Client call takes about 90 seconds:

 from suds.client import Client url = 'http://localhost:7080/webservices/WebServiceTestBean?wsdl' client = Client(url) 

After I run the last line above, I get a Client instance. Creating this client takes a lot of time. Does caching work with Python objects or is it limited to primitives like strings and integers?

Here, what I want to do in the code, the syntax is wrong, but it should convey what I want:

 from suds.client import Client if 'current_client' in cache: client = cache.get('current_client') else: url = 'http://localhost:7080/webservices/WebServiceTestBean?wsdl' client = Client(url) cache.put('current_client', client) 

Alternative dynamic language solution with Ruby

There is a Ruby Soap library called Savon and it very quickly analyzes these large wsdl and many xsd for those interested in the dynamics of a language solution instead of a static language. Soap libraries. I tried Savon for this particular case and it works very well.

+4
source share
4 answers

suds caches the WSDL and XSD files in one day by default, so that for each instance of the Client object, a separate URL request is not required.

90 seconds seems really a long time, is it the time spent waiting for the wsdl response, or was it spent parsing the wsdl? If it takes a long time to parse it, the built-in caching will not help.

I already did something similar before, but instead of a singleton template, I just used a global dictionary at the module level. This is a singleton noise-free template class .

Something like that:

 from suds.client import Client _clients = {} def get_client(name): if name not in _clients: _clients[name] = Client(url_for_name) return _clients[name] 
+3
source

Have you tried it ?

As for Python, the problem should not be a problem. The big problem with any cache is maintaining consistency, but how you do it depends on the application, not Python.

+1
source

If I understand your problem well, I think that you do not want to create a new Client () every time and which you want to cache so that you can get it; but I think that you complicate, and I suggest using a singleton pattern , this will allow you to create only one client instance and each you want to create a new instance, it will just return the old instance that was created.

Here is an example to help you understand what I offer.

 class MyClient(Client): __instance__ = None def __new__(cls, *args, **kws): if not cls.__instance__: cls.__instance__ = super(Client, cls).__new__(cls, *args, **kws) return cls.__instance__ 

NB: I wanted to use a borg pattern that looks like a singleton, but more beautiful, but I couldn't figure out how to not call Super. init (which takes a lot of time), and at the same time, it uses the same state, if anyone has a better idea of ​​how to use it using the Borg template, that would be great, but I don't think that borg chart may be useful in this case

Hope this helps

0
source

suds> = 0.3.5 r473 provides some URL caching. By default, http get (s), such as getting WSDL and importing XSD, are cached.

0
source

All Articles