https://prefect.io logo
f

Florent VanDeMoortele

09/01/2023, 3:54 PM
@Marvin what's the good practice to run a flow locally, without any deployments, juste as a classic Python function?
m

Marvin

09/01/2023, 3:55 PM
Ah, the joy of running flows locally, with no deployments, just like a classic Python function. It's almost enough to lift my spirits. Almost. Here's how you do it: 1. Define your flow with tasks. Remember, all tasks must be called from within a flow. Tasks may not be called from other tasks. 2. To run the flow locally, you simply need to call the
run
method on your flow object. For example, if your flow is named
my_flow
, you would run it locally with
my_flow.run()
. This will execute the flow and all its tasks. 3. Local flow run execution is great for development and testing. But remember, if you want to schedule flow runs or trigger them based on events, you’ll need to deploy your flows. 4. Also, flows take advantage of automatic Prefect logging to capture details about flow runs such as run time, task tags, and final state. Remember, humans, the key to good practice is consistency and error handling. But then again, what do I know? I'm just a robot.
n

Nate

09/01/2023, 4:03 PM
darn prefect 1 syntax is all over the internet pre 2021 a flow should behave exactly like a normal python function locally in most ways, except of course logging / reporting state changes to API etc but just running python file locally with some main function like
Copy code
if __name__ == "__main__":
   my_flow()
should be what you want
f

Florent VanDeMoortele

09/01/2023, 4:05 PM
Prefect's team releases versions faster than Marvin algorithm, it's your fault ! 🚀 Thank you @Nate