Watchdog provides a cross-platform Python API and optional watchmedo shell utility to react to file system changes.
Overview
Watchdog is a Python library for monitoring file and directory events on a machine. It exposes observers and event handlers so programs can schedule recursive watches on paths and run code when files are created, modified, moved, or deleted.
An optional watchmedo command-line tool can log filtered events, run shell commands in response to changes, and load tricks from YAML files that tie custom handler classes to patterns. The API supports context-manager style observer lifecycle for simpler cleanup in scripts.
Platform backends documented in the project include Linux inotify, macOS FSEvents and kqueue, BSD kqueue, Windows ReadDirectoryChangesW, and a polling fallback when native notifications are unsuitable such as some network filesystem setups. The library targets Python 3.11 and above and installs from PyPI, with an extra that includes watchmedo.
Watchdog is meant to be embedded in Python applications or invoked through watchmedo for automation, not deployed as a standalone network service.
Key features
- Cross-platform file system events
- Observer and handler API
- Optional watchmedo CLI
- Pattern filters and shell commands
- YAML-based tricks plugins
- Polling observer fallback
Use cases
- Auto-reload on code changes
- Logging directory activity
- Triggering builds on file edits
- Custom event-driven automation