Does anyone know how do we construct a python Asse...
# ask-community
s
Does anyone know how do we construct a python Asset or Resource within Dagster? For example, if I have a Python script on my system “foo.py”, what Dagster API can I use to turn this script into an Asset or Resource and then execute it? I am struggling with the Documentation. Thank you!
dagster bot responded by community 1
🤖 1
z
it might be best to keep it simple when getting started and just call your script from an
op
. So if you have a python script like this:
Copy code
#script_to_call.py
def do_something(input_param):
    #do the thing

if __name__ == '__main__':
    do_something("here's an input")
you could call that same function from an op in a different module like this:
Copy code
from script_to_call import do_something
from dagster import op, job

@op(config_schema={"input_param": str})
def do_something_op(context):
    return do_something(context.op_config["input_param"])

@job
def do_something_job():
    do_something_op()
then you can either call your job programmatically using
do_something_job.execute_in_process(run_config={"ops": {"do_something_op": {"config": {"input_param": "some-input"}}}})
or by adding your job to a
repository
and spinning up a dagit UI instance to run it from
if you need to call your script from the command-line, i.e. it's not importable from your dagster code, you can use the `dagster-shell` library like this:
Copy code
from dagster_shell import create_shell_command_op

from dagster import graph


@graph
def my_graph():
    a = create_shell_command_op('python script_to_call.py', name="a")
    a()
s
Thank you very much, this was very helpful!
🎉 1