Skip to main content

Using bare Python objects as resources

tip

You can scaffold resources from the command line by running dg scaffold defs dagster.resources <path/to/resources_file.py>. For more information, see the dg CLI docs.

When starting to build a set of assets or jobs, you may want to use a bare Python object without configuration as a resource, such as a third-party API client.

Dagster supports passing bare Python objects as resources. This follows a similar pattern to using a ConfigurableResource subclass; however, assets that use these resources must annotate them with ResourceParam. This annotation lets Dagster know that the parameter is a resource and not an upstream input.

src/<project_name>/defs/assets.py
import dagster as dg

# `ResourceParam[GitHub]` is treated exactly like `GitHub` for type checking purposes,
# and the runtime type of the github parameter is `GitHub`. The purpose of the
# `ResourceParam` wrapper is to let Dagster know that `github` is a dg.resource and not an
# upstream dg.asset.

@dg.asset
def public_github_repos(github: dg.ResourceParam[GitHub]):
return github.organization("dagster-io").repositories()
src/<project_name>/defs/resources.py
@dg.definitions
def resources():
return dg.Definitions(
resources={"github": GitHub(...)},
)