I'm looking for a cross-platform file monitoring python package? I know it is possible to monitor files on windows using pywin32, and there are packages working on Linux/Unix but does anyone know about a cross-platform one?

- 119,623
- 25
- 170
- 301

- 2,977
- 4
- 25
- 26
-
2Tim Golden has a very simple cross-platform method of polling a directory with os.listdir here: http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html – mechanical_meat Feb 28 '09 at 12:07
-
2What does "monitor" mean? Please provide some hint as to what you are trying to do. – S.Lott Feb 28 '09 at 12:08
5 Answers
I'm working on an MIT-licensed library that helps Python programs monitor file system events as portably as possible. There are differences that I'm trying to iron out. Highly alpha version at the moment:
Check it out here: http://github.com/gorakhargosh/watchdog/
Patches and contributions are welcome.

- 20,030
- 7
- 43
- 238

- 1,175
- 1
- 7
- 5
-
Thanks a lot, I was looking for a cross platform solution and watchdog is really helpful! – mtrovo Oct 17 '11 at 13:35
-
-
4
-
1This is definitely the must-be-accepted-answer. Works as charm :) Here is the usage of watchdog: http://pythonhosted.org/watchdog/quickstart.html – swdev Nov 30 '14 at 22:14
-
-
Just want to say that the project is still actively being developed and looks pretty awesome. Thanks! – Johndt Nov 03 '16 at 00:18
-
docs are awful, not helping at all ... just saying ... Example: 'patterns argument description: (Read-only) Patterns to allow matching event paths.', ohh it's reallly descriptive – Dawid Gosławski Nov 14 '16 at 09:32
-
2Last update was three years ago, should I still use this library or go for something like `watchgod`? – Marcus Mann Jul 02 '18 at 13:07
-
I'm going to make a warning against the library: it currently has an issue, where the watchdog will randomly stop working. – Mahrkeenerh Apr 14 '22 at 08:27
For Unix/Linux based systems, you should use File Alteration Monitor Python bindings to libfam.
For Windows based systems, you should tie into the Win32 API FindFirstChangeNotification
and related functions.
As for a cross platform way, I don't know about a good cross platform way. I think it would be best to build a module yourself that works on either OS that uses one of the 2 above methods after detecting what OS it is.

- 112,946
- 110
- 377
- 526

- 339,232
- 124
- 596
- 636
-
1Could you explain how to use the W32 API in an example... because I don't get that... – wishi Oct 25 '10 at 20:01
Also check out this option:
http://pypi.python.org/pypi/watchdog
Was used with a cross-platform app on Windows and OS X.

- 97
- 1
- 2
-
4Possibly because the author of watchdog posted about it in an answer a year earlier and there's not much in this response? Probably not worth a downvote, but not much worth an upvote either. – fencepost Dec 23 '11 at 19:06
-
2
-
1I never get it why an answer got downvoted. Here is the usage of watchdog: http://pythonhosted.org/watchdog/quickstart.html – swdev Nov 30 '14 at 22:13
I found this link, which talks about your problem. Although it doesn't really provide s solution/library, I think it will help. http://www.stepthreeprofit.com/2008/06/cross-platform-monitoring-of-filesystem.html
I don't think there is a cross-platform one yet, so you might want to roll your own.
I am inexperienced in this area so I am not really sure. I hope this helps.
Note
I stand corrected, gamin is available on cygwin as Adam Bernier pointed out to me in a comment. You may want to research other options on cygwin (if they exist).

- 5,155
- 3
- 32
- 38
-
Seems to be some good feedback for Gamin on Linux. FWIW, Gamin is listed in cygwin packages: http://cygwin.com/packages/ – mechanical_meat Feb 28 '09 at 12:12
-
The easiest way on Linux is to use inotifywait (given that your kernel is recent enough). You don't need any special bindings, inotifywait can be customized to print output lines on standard output in any way you want. Look and this question for a good example.
-
He specifically mentioned cross platform. inotifywait is only for linux – Quintin Par Jan 05 '10 at 18:56