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
mouad source share