Filesystem monitoring library for Python
Switch branches/tags
Nothing to show
Clone or download
ljmccarthy Update README.rst
Remove e-mail address.
Latest commit 4d84d98 Aug 27, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
fsmonitor Feat: Allow to override FSMonitor class Jul 4, 2018
tests Tests: Add tests for polling FSMonitor Jul 4, 2018
.gitignore
COPYING Added MIT/X11 license COPYING file. Nov 28, 2010
MANIFEST.in Tests(tox): Add tox.ini Jul 4, 2018
README.rst
setup.py Feat: Support Python 3 Jul 4, 2018
tox.ini Feat: Support Python 3 Jul 4, 2018

README.rst

fsmonitor - Filesystem Monitoring for Python

Supported Platforms

  • Linux 2.6 (inotify)
  • Windows (ReadDirectoryChangesW with I/O completion ports)
  • Any other platform (polling)

Supported Python versions

  • Python 2: tested with 2.7
  • Python 3: tested with 3.3+ on Linux

Installation

$ python setup.py install

Introduction

The fsmonitor module provides live filesystem monitoring. It can be used to monitor for events such as file creation, deletion, modification and so on:

from fsmonitor import FSMonitor

The FSMonitor class manages filesystem watches and is used to receive events. Call the add_dir_watch() method to add a directory watch to the monitor:

m = FSMonitor()
watch = m.add_dir_watch("/dir/to/watch")

Once a watch has been added, you can call read_events() to read a list of filesystem events. This is a blocking call and in some cases it might return an empty list, so it needs to be re-called repeatedly to get more events:

while True:
    for evt in m.read_events():
        print evt.action_name, evt.name

The FSMonitorThread class can be used to receive events asynchronously with a callback. The callback will be called from another thread so it is responsible for thread-safety. If a callback is not specified, the thread will collect events in a list which can be read by calling read_events().

More Details

See the example code in the examples directory.

Contact Details

Please report bugs on the GitHub issue tracker.