Watchfiles + Prefect: Real-time File Automation in 2026
Detect file changes instantly and trigger Prefect workflows automatically.
Practical Example
from watchfiles import watch
from prefect import flow, task
from loguru import logger
@task
def process_new_file(file_path: str):
logger.info(f"Processing new file: {file_path}")
# ETL or analysis logic here
@flow
def file_automation_flow():
for changes in watch("/data/incoming", recursive=True):
for _, path in changes:
if path.endswith(".csv"):
process_new_file(path)
if __name__ == "__main__":
file_automation_flow()
Conclusion
This pattern is perfect for data ingestion, log monitoring, and hot-folder processing in 2026.