<@ULVA73B9P> Migrating from Prefect 2 to 3 and it ...
# ask-marvin
a
@Marvin Migrating from Prefect 2 to 3 and it looks like
load_flow_from_script
is no longer available in the Python SDK. is there an equivalent function in 3?
m
thought for 46.1 seconds
In Prefect 3.x, the
load_flow_from_script
function has been replaced with a more streamlined approach using the
from_source()
method. Instead of loading a flow directly from a script, you'll want to use the following pattern:
Copy code
python
from prefect import flow

# Deploy a flow from a local script
flow.from_source(
    source="path/to/your/script.py",
    entrypoint="script.py:flow_function_name"
).deploy(name="your-deployment-name")
This new approach is part of Prefect 3.x's broader redesign that emphasizes more robust deployment mechanisms and better integration with modern infrastructure patterns. The
from_source()
method is more flexible and can handle both local scripts and remote sources. For example, if you previously had:
Copy code
python
# Prefect 2.x (old way)
from prefect.utilities.load import load_flow_from_script
flow = load_flow_from_script(path="path/to/script.py", flow_name="my_flow")
You would now use:
Copy code
python
# Prefect 3.x (new way)
from prefect import flow
deployment = flow.from_source(
    source="path/to/script.py",
    entrypoint="script.py:my_flow"
).deploy(name="my-deployment")
This change aligns with Prefect 3.x's shift toward work pools and workers (replacing the older agent-based system) and provides a more consistent way to handle flow deployments.
a
Thanks. I also was using
prefect deployment build
CLI command, which also seem to be removed in 3. Is there an equivalent in 3?