Steve Friedman
11/13/2025, 10:29 PM@flow on a class?Marvin
11/13/2025, 10:29 PMMarvin
11/13/2025, 10:34 PMdef run(self, ...)) decorated with @flow requires a self and Prefect won’t instantiate your class when loading the entrypoint, so it can’t be used as-is.
Recommended patterns:
1) Wrap the method with a module-level flow (most reliable)
from prefect import flow
class MyFlow:
def __init__(self, cfg: str):
self.cfg = cfg
def run(self, x: int) -> int:
# your logic here
return x + 1
@flow
def run_my_flow(x: int) -> int:
obj = MyFlow(cfg="prod")
return obj.run(x)
Then deploy this entrypoint:
prefect deploy ./path/to/file.py:run_my_flow
2) Make it a static/class method so it doesn’t need an instance (use with care)
- For staticmethod, keep @staticmethod outside so the @flow sees a plain function at class creation time:
class MyFlow:
@staticmethod
@flow
def run(x: int) -> int:
return x + 1
Entrypoint: ./path/to/file.py:MyFlow.run
Note: Avoid @flow on an instance method (self) — Python’s method binding won’t kick in after decoration, and Prefect cannot supply self.
If you share a small snippet of how your class is structured, I can suggest the cleanest refactor for your case.