published by | Adam Johnson |
---|---|
in blog | Adam Johnson |
original entry | Django: a pattern for settings-configured API clients |
Here’s an example of a common pattern in Django projects:
from acme.api import APIClient
from django.conf import settings
acme_client = APIClient(api_key=settings.ACME_API_KEY)
def order_anvil() -> None:
acme_client.anvils.order(...)
An API client is instantiated as a module-level variable based on some settings. This approach has some drawbacks …