https://dagster.io/ logo
#ask-community
Title
# ask-community
l

Louis Auneau

07/28/2023, 8:13 PM
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

Lee Littlejohn

07/28/2023, 8:38 PM
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

Louis Auneau

07/31/2023, 2:45 PM
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

Lee Littlejohn

07/31/2023, 8:23 PM
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

Louis Auneau

07/31/2023, 8:26 PM
Oh nice ! That was exactly what I needed, thanks!
l

Lee Littlejohn

07/31/2023, 8:27 PM
👍