Assets talk to databases, APIs and storage. Instead of creating those clients inside every asset, define a resource: a class that subclasses dg.ConfigurableResource, declares its settings as typed fields and exposes methods.
class ShopApiResource(dg.ConfigurableResource):
base_url: str
token: str
def client(self):
return shop.ShopApi(self.base_url, self.token)
Register an instance under a key in Definitions(resources={"shop_api": ShopApiResource(...)}). An asset asks for it with a parameter whose name is the key and whose annotation is the class: def api_orders(shop_api: ShopApiResource).
Dagster checks at load time that every resource an asset needs is provided, and the error names the missing key. Because the asset only knows the type, tests and other environments can pass a different instance, for example one pointing at a sandbox.
A resource registered under the key shop_api and an asset that receives it.