talira

watchdog

Python API and shell utilities to monitor filesystem events

open sourceApache-2.0free

watchdog is a Python library for monitoring filesystem events, with an optional watchmedo command that logs changes or runs a shell command when files change. It uses inotify on Linux, FSEvents or kqueue on macOS, kqueue on the BSDs and ReadDirectoryChangesW on Windows, and can fall back to polling directory snapshots. watchmedo can also run tricks from a tricks.yaml file.

Problems it solves

  • run a function in my Python script whenever a file in a folder changes
  • rerun a shell command automatically when I save a file
  • watch a directory for new files in Python on Linux, macOS and Windows

Features

  • inotify, FSEvents, kqueue and ReadDirectoryChangesW observers
  • polling observer for any OS and for network shares
  • watchmedo command to log changes or run a shell command
  • tricks.yaml files for watchmedo
  • builds and runs under free-threaded CPython

Limitations

  • With kqueue, the open file limit must be raised above the number of files watched, and it doesn't scale to large deeply nested trees1
  • Its thread safety under free-threaded CPython hasn't been fully audited, notably the macOS FSEvents interface1