elgreco
02/26/2024, 7:01 PMScout
02/26/2024, 7:01 PMresource_defs
parameter when decorating your function with @observable_source_asset
. The resource_defs
parameter allows you to specify resource definitions that may be required by the asset. Here is an example based on the documentation: python from dagster import observable_source_asset, ResourceDefinition # Define your resources my_resource = ResourceDefinition(...) @observable_source_asset(resource_defs={'my_resource': my_resource}) def my_observable_asset(): # Your asset logic here ...
In this example, my_resource
is a ResourceDefinition
that you want to make available to my_observable_asset
. By including it in the resource_defs
dictionary with the key 'my_resource'
, you can then access this resource within your asset definition using the provided context. Please note that the resource_defs
parameter is marked as experimental in the documentation, which means that this API may change in future versions of Dagster, even between dot releases. Always refer to the latest documentation for the most up-to-date information on using this feature.elgreco
02/26/2024, 7:03 PMScout
02/26/2024, 7:03 PMrequired_resource_keys
parameter, which specifies the set of resource keys that the asset requires. Here's an example of how you might define an observable source asset factory with `required_resource_keys`: python from dagster import observable_source_asset # Assuming 'my_resource' is a key for a resource defined globally in your repository @observable_source_asset(required_resource_keys={'my_resource'}) def my_asset(context): # You can access the resource using the context my_resource_instance = context.resources.my_resource # Your asset logic here ...
In this example, my_asset
is an observable source asset that requires a resource with the key 'my_resource'
. By specifying this in required_resource_keys
, Dagster knows to provide the resource associated with that key to the asset when it is materialized. If you have multiple resources, you can include all the required keys in the set: python @observable_source_asset(required_resource_keys={'my_resource', 'another_resource'}) def my_asset(context): # Access multiple resources my_resource_instance = context.resources.my_resource another_resource_instance = context.resources.another_resource # Your asset logic here ...
These examples show how to specify resource dependencies by their keys for observable source assets. The actual resource instances are defined elsewhere in your repository, and you are simply telling Dagster which ones this particular asset needs to operate. Remember to always check the latest Dagster documentation for the most current practices, as APIs and features can evolve over time.