Chris Marriott
05/22/2026, 2:20 PMMarvin
05/22/2026, 2:20 PMMarvin
05/22/2026, 2:22 PMwatchdog, inotify, or another filesystem watcher
- When a file lands, call Prefect to create a flow run for a deployment
- Best if you want near-real-time behavior
3. Emit a custom Prefect event, then use an automation
- Your watcher script detects the file
- It emits a custom event like file.landed
- A Prefect automation triggers the deployment from that event
- Nice if you want to stay within Prefect’s event/automation model
A simple mental model is:
text
filesystem watcher/poller -> Prefect event or deployment run request -> flow starts
If you want the easiest setup, I’d recommend a scheduled deployment that polls the directory.
If you want true event-driven behavior, I’d recommend an external watcher that either:
- calls the deployment run API directly, or
- emits a custom event that an automation listens for
Example watcher pattern in Python:
python
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import asyncio
from prefect.client.orchestration import get_client
DEPLOYMENT_ID = "your-deployment-id"
class Handler(FileSystemEventHandler):
def on_created(self, event):
if event.is_directory:
return
if event.src_path.endswith(".csv"):
asyncio.run(trigger_deployment(event.src_path))
async def trigger_deployment(path):
async with get_client() as client:
await client.create_flow_run_from_deployment(
deployment_id=DEPLOYMENT_ID,
parameters={"file_path": path},
)
observer = Observer()
observer.schedule(Handler(), "/data/incoming", recursive=False)
observer.start()
observer.join()
A few relevant docs:
- Deployments
- Automations
- Events
- Prefect events Python API
If you want, I can give you:
- a polling flow example
- an event-driven automation example
- or a full local-directory watcher → Prefect deployment example