Skip to main content

Thread-based interface to file system observation primitives.

Project description


MacFSEvents is a Python library that provides thread-safe directory observation primitives using callbacks. It wraps the Mac OS X FSEvents API in a C-extension.


  • Mac OS X 10.5+ (Leopard)

This software was written by Malthe Borch <>. The pyfsevents module by Nicolas Dumazet was used for reference.


At this time of writing there are three other libraries that integrate with the FSEvents API:


These use the PyObjC bridge infrastructure which most applications do not need.


Not thread-safe (API is not designed to support it).


Obsolete bindings to the socket API by John Sutherland.

These issues have been addressed in MacFSEvents. The library provides a clean API and has full test coverage.

Note that pyfsevents has bindings to the file descriptor observation primitives. This is not currently implemented by the present library.


Made available as-is under the BSD License.


To observe a directory structure (recursively) under path, we set up an observer thread and schedule an event stream:

from fsevents import Observer
observer = Observer()

def callback(FileEvent):

from fsevents import Stream
stream = Stream(callback, path)

Streams can observe any number of paths; simply pass them as positional arguments (or using the * operator):

stream = Stream(callback, *paths)

To start the observer in its own thread, use the start method:


To start the observer in the current thread, use the run method (it will block the thread until stopped from another thread):

The callback function will be called when an event occurs. A FileEvent instance is passed to the callback and has 3 attributes: mask, cookie and name. name parameter contains the path at which the event happened (may be a subdirectory) while mask parameter is the event mask [1].

To stop observation, simply unschedule the stream and stop the observer:


While the observer thread will automatically join your main thread at this point, it doesn’t hurt to be explicit about this:


We often want to know about events on a file level; to receive file events instead of path events, pass in file_events=True to the stream constructor:

def callback(event):

stream = Stream(callback, path, file_events=True)

The event object mimick the file events of the inotify kernel extension available in newer linux kernels. It has the following attributes:

The mask field is a bitmask representing the event that occurred.
The cookie field is a unique identifier linking together two related but separate events. It is used to link together an IN_MOVED_FROM and an IN_MOVED_TO event.
The name field contains the name of the object to which the event occurred. This is the absolute filename.

Note that the logic to implement file events is implemented in Python; a snapshot of the observed file system hierarchies is maintained and used to monitor file events.

[1]See FSEventStreamEventFlags for a reference. To check for a particular mask, use the bitwise and operator &.


0.2.8 (2012-06-09)


  • Fix recursive snapshot. [thomasst]
  • Use os.lstat instead of os.stat to correctly detect symlinks. [thomasst]

0.2.7 (2012-05-29)

  • Added support for IN_ATTRIB. [thomasst]

0.2.6 (2012-03-17)

  • Fixed compilation problen on newer platforms. [nsfmc]

0.2.5 (2012-02-01)

  • Ignore files that don’t exist while recursing. [bobveznat]

0.2.4 (2010-12-06)

  • Prevent crashes on recursive folder delete and multiple folder add. [totolici].

0.2.3 (2010-07-27)

  • Fixed broken release.

0.2.2 (2010-07-26)

  • Python 2.4 compatibility [howitz]
  • Fixed an issue where the addition of a new directory would crash the program when using file event monitoring [andymacp].

0.2.1 (2010-04-27)

  • Fixed an import issue [andymacp].

0.2 (2010-04-26)

  • Fixed issue where existing directories would be reported along with a newly created one [marcboeker].
  • Added support for file event monitoring.
  • Fixed reference counting bug which could result in a segmentation fault.

0.1 (2009-11-27)

  • Initial public release.

Project details

Release history Release notifications

History Node


History Node


History Node


History Node


History Node


History Node


History Node


This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
MacFSEvents-0.2.8.tar.gz (13.2 kB) Copy SHA256 hash SHA256 Source None Jun 9, 2012

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page