Kurt Sys (Vintecc)
10/21/2025, 12:49 PMif __name__ == "__main__":
deployment_id = my-flow.deploy(
name="some-flow",
work_pool_name="workpool",
image="<my:image>",
build=False,
push=False,
version="local",
tags=[],
description=None,
entrypoint_type=EntrypointType.MODULE_PATH,
job_variables={
...
},
)
print(f"Created/updated deployment: {deployment_id}")
How can I avoid to have my-flow imported. What I actually want is to say: make a deployment with entrypoint "some.package.as.string.file.py::flow_function".Marvin
10/21/2025, 12:49 PMMarvin
10/21/2025, 12:55 PMsome.package.as.string.file.flow_function
- File path (single colon): some/package/as/string/file.py:flow_function
Note: Double-colon :: is not supported.
Example using Flow.from_source and deploying (no direct import of my_flow):
from prefect.flows import Flow
from prefect.types.entrypoint import EntrypointType
if __name__ == "__main__":
# Pick ONE of the two styles:
# 1) Module path (requires the package to be importable from the project root)
entrypoint = "some.package.as.string.file.flow_function"
entrypoint_type = EntrypointType.MODULE_PATH
# 2) File path (single colon)
# entrypoint = "some/package/as/string/file.py:flow_function"
# entrypoint_type = EntrypointType.FILE_PATH
# 'source' can be "." (local project root) or a remote repo URL, e.g. "<https://github.com/org/repo>"
flow_ref = Flow.from_source(
source=".",
entrypoint=entrypoint,
)
deployment_id = flow_ref.deploy(
name="some-flow",
work_pool_name="workpool",
image="<my:image>",
build=False,
push=False,
version="local",
tags=[],
description=None,
entrypoint_type=entrypoint_type, # optional — Prefect auto-detects based on presence of ':'
job_variables={
# ...
},
)
print(f"Created/updated deployment: {deployment_id}")
A few tips:
- Use MODULE_PATH if your package is importable (i.e., project root on PYTHONPATH or installed). Otherwise, prefer FILE_PATH with a single colon.
- You can omit entrypoint_type and let Prefect auto-detect it from the string.
- For remote sources (e.g., GitHub), pass the repo URL to source, e.g. source="<https://github.com/owner/repo>".
Docs for reference:
- Flow.from_source API
- Deploy via Python
- EntrypointType
Quick question to tailor this: where does your flow code live (local package vs raw file path vs Git repo)? That will determine the best source and entrypoint style.Kurt Sys (Vintecc)
10/21/2025, 1:03 PMflow_ref. This can be anything, it actaully doesn't matter, since we pass the real entrypoint anyway?Marvin
10/21/2025, 1:03 PMMarvin
10/21/2025, 1:03 PMflow_ref isn’t special. It’s just the Flow object you get back from Flow.from_source so you can call .deploy() on it. You can skip naming it and just chain the calls.
What matters is:
- Flow.from_source(source, entrypoint) creates a Flow object that references your code by entrypoint string (it doesn’t need to import your flow at deploy time).
- .deploy() is an instance method, so you need that Flow object (even if you don’t store it in a variable).
So you can write it inline like this:
from prefect.flows import Flow
from prefect.types.entrypoint import EntrypointType
if __name__ == "__main__":
deployment_id = Flow.from_source(
source=".", # or a repo URL like "<https://github.com/org/repo>"
entrypoint="some.package.as.string.file.flow_function", # module path
).deploy(
name="some-flow",
work_pool_name="workpool",
image="<my:image>",
build=False,
push=False,
version="local",
tags=[],
description=None,
# optional — Prefect auto-detects from the string; include if you want to be explicit:
entrypoint_type=EntrypointType.MODULE_PATH,
job_variables={
# ...
},
)
print(f"Created/updated deployment: {deployment_id}")
Entrypoint formatting reminder:
- Module path (no .py file, no colon): some.package.as.string.file.flow_function
- File path (single colon): some/package/as/string/file.py:flow_function
- Double-colon :: is not supported.
In short: the object returned by Flow.from_source isn’t arbitrary, but you don’t need to name it — just chain .deploy(). The actual import of your flow code happens later by the worker at run time using the entrypoint you provided.Kurt Sys (Vintecc)
10/21/2025, 1:08 PMMarvin
10/21/2025, 1:08 PMMarvin
10/21/2025, 1:12 PMfrom prefect.deployments.runner import RunnerDeployment
from prefect.deployments import deploy
deployment = RunnerDeployment(
name="some-flow",
entrypoint="some.package.as.string.file.flow_function", # module path; no colon
work_pool_name="workpool",
job_variables={
# For Docker work pools:
"image": "<my:image>",
# Add any other worker-specific fields as needed
},
version="local",
tags=[],
description=None,
)
deployment_id = deploy(deployment, build=False, push=False)[0]
print(f"Created/updated deployment: {deployment_id}")
Notes:
- Module path uses dots (e.g., pkg.subpkg.module.flow_func), not double-colons.
- If you prefer file path style, use path/to/file.py:flow_function (single colon).
Pattern B: Let Prefect pull your code from source (if not baked into the image)
from prefect.runner.storage import create_storage_from_source
from prefect.deployments.runner import RunnerDeployment
from prefect.deployments import deploy
storage = create_storage_from_source(".") # or "<https://github.com/org/repo>"
deployment = RunnerDeployment.from_storage(
storage=storage,
entrypoint="path/to/file.py:flow_function", # or module path
name="some-flow",
work_pool_name="workpool",
job_variables={"image": "<my:image>"},
version="local",
)
deployment_id = deploy(deployment, build=False, push=False)[0]
print(f"Created/updated deployment: {deployment_id}")
Why this works:
- The Flow object isn’t required. RunnerDeployment holds the metadata (name, entrypoint, storage, work pool, job vars) Prefect needs to register the deployment. The actual import of your code happens later, inside the worker, using the entrypoint string and your image.
Docs for reference:
- Deploy via Python
- Flow.from_source (not required in your case, but related)
- Runner storage options
Quick follow-up: Which work pool are you using (Docker or Kubernetes)? The job_variables schema differs slightly per pool, and I can tailor the example for your setup.Kurt Sys (Vintecc)
10/21/2025, 1:29 PMMarvin
10/21/2025, 1:29 PMMarvin
10/21/2025, 1:29 PMjob_variables snippet tailored to it.