Watchgod is a Python library designed for simple file watching and code reloading. It was last released as version 0.8.2 in April 2022. This package is now considered inactive and has been superseded by `watchfiles`, which offers a more performant Rust-based backend for file system notifications. `watchgod` relies on file polling for change detection.
pip install watchgodVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `watchgod.watch` to detect file system changes in a specified directory. It creates a temporary directory and file, then watches it for a short period. For real-world use, you would typically run the `watch` loop indefinitely.
Migrate to `watchfiles`. Install with `pip install watchfiles`. Update import statements from `watchgod` to `watchfiles`. Be aware of potential API changes, especially regarding `watcher_cls` (replaced by `watch_filter`) and `target` arguments for `run_process` (now keyword-only). Refer to the `watchfiles` migration guide.
For high-performance, real-time file watching, use the `watchfiles` library, its successor, which utilizes a Rust-based backend for OS-native file system event handling.
Switch to `watchfiles` to ensure you receive ongoing feature development, performance improvements, and non-critical bug fixes.
pip install watchgod
Ensure the watched path is directly accessible and consider adjusting the `poll_interval`. For more robust, event-driven detection, migrate to `watchfiles`.
from watchgod import watch
watch('.', 'src', callback=my_callback) # Pass paths as positional argumentsfrom watchgod import watch
import os
# Ensure the directory exists or provide a valid path
watched_dir = 'my_project_dir'
if not os.path.exists(watched_dir):
os.makedirs(watched_dir)
watch(watched_dir, callback=my_callback)No dependency data recorded yet.