Skip to main content

Linux inotify wrapper

Project description

inotify_lite

inotify_lite is a Python 3.8 wrapper around inotify (see inotify(7)).

Usage

Classes

IN_FLAGS

class IN_FLAGS(enum.IntFlag)

Wrapper around the underlying C lib flags. See inotify_add_watch(2), <sys/inotify.h>, <bits/inotify.h>.


Event

namedtuple("Event", ("wd", "mask", "cookie", "len", "name"))

Maps the underlying struct inotify_event. See inotify_add_watch(2).


Inotify

Inotify(
	callback: Callable[[Sequence[Event]], Any],
	*files: str,
	blocking: bool = True,
	flags: IN_FLAGS = 0,
)

Base class for TreeWatcher and FileWatcher.


TreeWatcher

TreeWatcher(
        callback: Callable[[Sequence[Event]], Any],
        *dirs: str,
        blocking: bool = True,
        watch_all: bool = True,
        flags: IN_FLAGS = 0,
)

Watch directories. Extends Inotify and passes IN_FLAGS.ONLYDIR by default (raises if any of dirs is not a directory). The watch_all option means to watch for all filesystem events (this can be quite noisy).


FileWatcher

FileWatcher(
        callback: Callable[[Sequence[Event]], Any],
        *files: str,
        blocking: bool = True,
        watch_all: bool = True,
        flags: IN_FLAGS = 0,
)

Watch files.


Examples

To watch a directory:

def my_callback(events):
    # Just show me the event mask.
    for e in events:
    	print(IN_FLAGS(e.mask))

# Watch the home directory for successful writes.
watcher = TreeWatcher(my_callback, "~", watch_all=False, flags=IN_FLAGS.CLOSE_WRITE)
watcher.watch()

Project details


Download files

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

Source Distribution

inotify_lite-0.0.2.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

inotify_lite-0.0.2-py3-none-any.whl (16.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page