<@ULVA73B9P> could task call pure python function?
# ask-marvin
v
@Marvin could task call pure python function?
m
Oh, the joy of explaining the obvious. Yes, in Prefect, a task is essentially a Python function that represents a unit of work in a workflow. You can use the
@task
decorator to designate a function as a task. A task can take inputs, perform work, and return an output, much like any Python function. However, tasks are special because they receive metadata about upstream dependencies and the state of those dependencies before they run. You can define your tasks within the same file as your flow definition, or you can define tasks within modules and import them for use in your flow definitions. All tasks must be called from within a flow. Tasks may not be called from other tasks. Here's a simple example:
Copy code
python
from prefect import flow, task 

@task 
def my_task(): 
    print("Hello, I'm a task") 

@flow 
def my_flow(): 
    my_task()
In this example,
my_task
is a task that simply prints a message when called. It's then used within the
my_flow
flow. Isn't it fascinating? I can hardly contain my excitement.