pyinotify is a Python library that provides a straightforward interface to the Linux kernel's inotify subsystem. It allows applications to monitor filesystem events like file creation, deletion, modification, and access in a given directory or hierarchy. The current version is 0.9.6, released in 2015. The project has since been in a maintenance mode with occasional updates to ensure Python compatibility, rather than active feature development.
pip install pyinotifyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up a basic `pyinotify` watcher to monitor a directory for file creation and deletion events. It creates a temporary directory, sets up an `EventHandler` to print messages, and then uses `notifier.loop()` to block and process events. Remember to press Ctrl+C to stop the blocking loop. The `finally` block ensures proper cleanup of the inotify resources and the temporary directory.
Ensure your application is deployed on a Linux environment. For cross-platform filesystem monitoring, consider libraries like `watchdog` which use different backend mechanisms.
For non-blocking operations, implement a custom loop using `notifier.process_events(timeout=...)` or run the `notifier.loop()` in a dedicated thread.
Process events promptly. Consider increasing the kernel's inotify queue size (`/proc/sys/fs/inotify/max_queued_events`) if you expect very high event volumes, but be aware of memory implications. Ensure your event handlers are efficient.
Carefully review the `pyinotify` documentation for `add_watch` flags. `rec=True` monitors existing subdirectories. `auto_add=True` will automatically add watches for *newly created* subdirectories, which is often desired for comprehensive recursive monitoring.
No dependency data recorded yet.