A common pattern in Django projects is to instantiate an API client as a module-level variable based on settings, which has drawbacks, especially during tests and with expensive clients. An alternative pattern involves using functools.cache to instantiate the client on first use and resetting the cache when settings change using Django's setting_changed signal. This approach improves efficiency and testability.
1 Comment
Sort: