A set of definitions to be explicitly available and loadable by Dagster tools.
Example usage:
defs = Definitions(
assets=[asset_one, asset_two],
schedules=[a_schedule],
sensors=[a_sensor],
jobs=[a_job],
resources={
"a_resource": some_resource,
}
)
Dagster separates user-defined code from system tools such the web server and the daemon. Rather than loading code directly into process, a tool such as the webserver interacts with user-defined code over a serialization boundary.
These tools must be able to locate and load this code when they start. Via CLI arguments or config, they specify a Python module to inspect.
A Python module is loadable by Dagster tools if there is a top-level variable
that is an instance of Definitions.
Before the introduction of Definitions,
@repository was the API for organizing defintions.
Definitions provides a few conveniences for dealing with resources
that do not apply to old-style @repository declarations:
It takes a dictionary of top-level resources which are automatically bound
(via with_resources) to any asset passed to it.
If you need to apply different resources to different assets, use legacy
@repository and use
with_resources as before.
The resources dictionary takes raw Python objects, not just instances
of ResourceDefinition. If that raw object inherits from
IOManager, it gets coerced to an IOManagerDefinition.
Any other object is coerced to a ResourceDefinition.
Returns an object that can load the contents of assets as Python objects.
Invokes load_input on the IOManager associated with the assets. Avoids
spinning up resources separately for each asset.
Usage:
with defs.get_asset_value_loader() as loader:
asset1 = loader.load_asset_value("asset1")
asset2 = loader.load_asset_value("asset2")
Get a job definition by name. If you passed in a an UnresolvedAssetJobDefinition
(return value of define_asset_job()) it will be resolved to a JobDefinition when returned
from this function.
Load the contents of an asset as a Python object.
Invokes load_input on the IOManager associated with the asset.
If you want to load the values of multiple assets, it’s more efficient to use
get_asset_value_loader(), which avoids spinning up
resources separately for each asset.
asset_key (Union[AssetKey, Sequence[str], str]) – The key of the asset to load.
python_type (Optional[Type]) – The python type to load the asset as. This is what will be returned inside load_input by context.dagster_type.typing_type.
partition_key (Optional[str]) – The partition of the asset to load.
The contents of an asset as a Python object.