Hello! I was wondering if there was any way to cre...
# ask-community
l
Hello! I was wondering if there was any way to create a configurable, third party API resource with the new Pythonic resources ? Doesn’t look so looking at the documentation, which is kind of a regression compared to the @resource. Thank you by advance.
l
this is the answer to your previous question (same question really though, right?) as well https://docs.dagster.io/concepts/resources#managing-state-in-resources
make the
setup_for_execution
function set your private attribute, which should be your client
like
Copy code
class BespokeResource(ConfigurableResource):
    config_value: str|None

    _client: YourClientType

    def setup_for_execution(self, context):
        if self.config_value:
            self._client = YourClient(config_value)
        else:
            self._client = YourClient()
then other functions can either use the client directly, or you can have another function return the client directly
Copy code
def get_client(self):
    return self._client
or
Copy code
def use_client(self, *args):
    self._client(*args)
with an asset looking like
Copy code
@asset
def my_asset(bespoke_resource: BespokeResource):
    your_client = bespoke_resource.get_client()
l
Indeed, seems like a good option, but this implies to change our entire code-base. I am try to do it directly with inheritance, hopefully I can make it work.
l
in that case,
IAttachDifferentObjectToOpContext
may be helpful - check out how the dagster_aws integration handles the s3 resource for both styles here
one returns the other, so the resource inside the op/asset is the client itself without an additional call
at least future code can be written to use the pythonic resources natively
l
Oh nice ! That was exactly what I needed, thanks!
l
👍