Differential D8684 Diff 40807 examples/docs_snippets/docs_snippets/legacy/data_science/download_file.py
Changeset View
Changeset View
Standalone View
Standalone View
examples/docs_snippets/docs_snippets/legacy/data_science/download_file.py
from urllib.request import urlretrieve | from urllib.request import urlretrieve | ||||
from dagster import Field, OutputDefinition, String, solid | from dagster import Field, OutputDefinition, String, solid | ||||
from dagster.utils import script_relative_path | from dagster.utils import script_relative_path | ||||
@solid( | @solid( | ||||
name="download_file", | name="download_file", | ||||
config_schema={ | config_schema={ | ||||
"url": Field(String, description="The URL from which to download the file"), | "url": Field( | ||||
"path": Field(String, description="The path to which to download the file"), | String, description="The URL from which to download the file" | ||||
), | |||||
"path": Field( | |||||
String, description="The path to which to download the file" | |||||
), | |||||
}, | }, | ||||
output_defs=[ | output_defs=[ | ||||
OutputDefinition( | OutputDefinition( | ||||
String, name="path", description="The path to which the file was downloaded" | String, | ||||
name="path", | |||||
description="The path to which the file was downloaded", | |||||
) | ) | ||||
], | ], | ||||
description=( | description=( | ||||
"A simple utility solid that downloads a file from a URL to a path using " | "A simple utility solid that downloads a file from a URL to a path using " | ||||
"urllib.urlretrieve" | "urllib.urlretrieve" | ||||
), | ), | ||||
) | ) | ||||
def download_file(context): | def download_file(context): | ||||
output_path = script_relative_path(context.solid_config["path"]) | output_path = script_relative_path(context.solid_config["path"]) | ||||
urlretrieve(context.solid_config["url"], output_path) | urlretrieve(context.solid_config["url"], output_path) | ||||
return output_path | return output_path |