Backend Mixins

As every backend needs a way to create itself, the ramos.mixins module provides mixin classes for this task which might be repetitive otherwise.


from ramos.mixins import SingletonCreateMixin

class BaseBackend:

    def do_something(self):

class MyBackend(SingletonCreateMixin, BaseBackend):

    def do_something(self):
        # do something else

backend = MyBackend.create()
other = MyBackend.create()

assert backend is other  # True


The inherited class will return always the same instance of the backend in every call of create.


The inherited class will return a new instance of itself in every call of create.

caveat: When ThreadSafeCreateMixin is used with args and kwargs, every backend of the same type should use it as well, so that the backend pool can create every backend instance using the exact same parameters.

Pool Mixins


The inherited class will have the option to return a default backend based on the SETTINGS_KEY value that will exist in your settings.

from ramos.mixins import DefaultBackendMixin
from ramos.pool import BackendPool

class MyBackendPool(DefaultBackendMixin, BackendPool):

backend = MyBackendPool.get_default()