Often in Django I want to create and configure some object at startup, and have it available everywhere. For example a third-party API client.
So when django starts I want to do this:
from some.thirdparty import ThirdPartyClient
from django.conf import settings
...
my_thirdparty_client = ThirdPartyClient(configstring=settings.SOME_CONFIG_ITEM)
And then in a view somewhere I want to do this:
from somewhere import my_thirdparty_client
def whatever(request):
my_thirdparty_client.do_stuff()
my_thirdparty_client.do_even_more_stuff()
Obviously I understand that I can instantiate the client at the start of the view, but if initalizing the instance is expensive I don't want to do it on every request.
What is the idiomatic Django way of creating these kinds of objects that I want to share between views?