whatisgithub

What is watchdog?

gorakhargosh/watchdog — explained in plain English

Analysis updated 2026-06-24

7,335PythonAudience · developerComplexity · 2/5LicenseSetup · easy

In one sentence

A Python library and CLI tool that watches directories for file changes and automatically runs your code in response, supporting Linux, macOS, Windows, and FreeBSD with a 15-line setup.

Mindmap

mindmap
  root((Watchdog))
    What it does
      Watch directories
      Detect file changes
      Trigger actions
    How to use
      Python event handlers
      watchmedo CLI tool
      YAML tricks config
    Platform support
      Linux inotify
      macOS FSEvents
      Windows ReadDirChanges
    Events detected
      Created modified
      Moved deleted
      Recursive watching
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Auto-reload a development server whenever source files change without manually restarting it

USE CASE 2

Run your test suite automatically every time you save a Python or source file

USE CASE 3

Define complex file-watching automation in a YAML tricks file without writing any Python code

USE CASE 4

Copy or process files automatically whenever new files are added to a watched directory

What is it built with?

PythoninotifyFSEventskqueueYAML

How does it compare?

gorakhargosh/watchdogapple/ml-fastvlmaxi0mx/ipwndfu
Stars7,3357,3377,333
LanguagePythonPythonPython
Setup difficultyeasyhardmoderate
Complexity2/54/54/5
Audiencedeveloperresearcherresearcher

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Editors like Vim that use backup files for saving may not trigger expected modification events, very large directory trees with kqueue need the OS file descriptor limit increased.

Use, modify, and distribute freely for any purpose including commercial use with attribution under the Apache License 2.0.

So what is it?

Watchdog is a Python library and command-line tool that watches directories for file changes and runs code in response. When a file is created, modified, moved, or deleted, watchdog notices and can trigger any action you define. Developers use it to auto-reload servers when code changes, run tests when source files save, or copy files whenever they are updated. Using it from Python involves creating an event handler class with methods that get called when specific events occur, then starting an Observer that monitors a directory. The observer can watch recursively, meaning changes in subdirectories trigger events as well. A code example in the README shows the full setup takes about fifteen lines of Python. The library also ships with an optional command-line utility called watchmedo. Without writing any Python, you can use watchmedo to log all file events in a directory, run shell commands when files matching a pattern change, or define complex automation through a YAML configuration file called tricks.yaml. The tricks system lets plugin authors write reusable event handlers that other users can reference by class name in their YAML config. Watchdog works on Linux using inotify, on macOS using FSEvents or kqueue, on FreeBSD using kqueue, and on Windows using the ReadDirectoryChangesW interface. A slower polling fallback is available for environments where none of those are accessible. The README notes a few edge cases: monitoring very large directory trees with kqueue requires increasing the operating system file descriptor limit, and editors like Vim that use backup files for saving may not trigger the expected modification events. Install with pip using pip install watchdog or pip install 'watchdog[watchmedo]' to include the CLI tool. Python 3.9 or higher is required. The project is licensed under the Apache License 2.0.

Copy-paste prompts

Prompt 1
Set up watchdog to auto-restart my Flask dev server whenever any .py file changes, show me the complete Python event handler code
Prompt 2
Use watchmedo to run pytest automatically whenever a file matching *.py changes in my src/ directory, show me the command
Prompt 3
Write a watchdog event handler that copies any new .jpg file dropped into an input folder to a backup directory
Prompt 4
Create a watchdog tricks.yaml file that runs a shell build script when files in src/ change and logs all events to a file

Frequently asked questions

What is watchdog?

A Python library and CLI tool that watches directories for file changes and automatically runs your code in response, supporting Linux, macOS, Windows, and FreeBSD with a 15-line setup.

What language is watchdog written in?

Mainly Python. The stack also includes Python, inotify, FSEvents.

What license does watchdog use?

Use, modify, and distribute freely for any purpose including commercial use with attribution under the Apache License 2.0.

How hard is watchdog to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is watchdog for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.