Skip to main content
inotipy is a high-level Python wrapper for the Linux
[`inotify(7)`](http://man7.org/linux/man-pages/man7/inotify.7.html) API,
that is designed to work with
[`asyncio`](https://docs.python.org/3/library/asyncio.html) event loops
in Python 3.5 or later. This lets you efficiently monitor one or more
files or directories for interesting happenings, without having to
continually poll the filesystem. But note, however, that if events are
coming too thick and fast, the kernel is liable to start dropping
them, which will be reported to you by events with the `IN.Q_OVERFLOW`
bit set.


Basic Usage
===========

Let us say there is a directory, initially empty, called “test”.
The following script monitors that for changes:

import sys
import asyncio
import inotipy

loop = asyncio.get_event_loop()

paths_to_watch = ["test"] # edit as necessary

async def mainline() :
watcher = inotipy.Watcher.create()
for path in paths_to_watch :
watcher.watch(path, inotipy.IN.ALL_EVENTS)
#end for
while True :
event = await watcher.get()
sys.stdout.write("Got event: %s\n" % repr(event))
#end while
#end mainline

loop.run_until_complete(mainline())

Suppose we start the script, and then in another terminal session
perform the following series of command-line actions:

$ echo hi >test/f1
$ mv test/f1 test/f2
$ cat test/f2
$ rm test/f2
$ rmdir test

then we should see the script report an event stream something like
this:

Got event: Event(1, [<EVENT_BIT.CREATE: 8>], 0, 'f1')
Got event: Event(1, [<EVENT_BIT.OPEN: 5>], 0, 'f1')
Got event: Event(1, [<EVENT_BIT.MODIFY: 1>], 0, 'f1')
Got event: Event(1, [<EVENT_BIT.CLOSE_WRITE: 3>], 0, 'f1')
Got event: Event(1, [<EVENT_BIT.MOVED_FROM: 6>], 217185, 'f1')
Got event: Event(1, [<EVENT_BIT.MOVED_TO: 7>], 217185, 'f2')
Got event: Event(1, [<EVENT_BIT.OPEN: 5>], 0, 'f2')
Got event: Event(1, [<EVENT_BIT.ACCESS: 0>], 0, 'f2')
Got event: Event(1, [<EVENT_BIT.CLOSE_NOWRITE: 4>], 0, 'f2')
Got event: Event(1, [<EVENT_BIT.DELETE: 9>], 0, 'f2')
Got event: Event(1, [<EVENT_BIT.DELETE_SELF: 10>], 0, '')
Got event: Event(1, [<EVENT_BIT.IGNORED: 15>], 0, '')

That should give you the basic flavour. For more elaborate examples,
see my `inotipy_examples` repo
([GitLab](https://gitlab.com/ldo/inotipy_examples),
[GitHub](https://github.com/ldo/inotipy_examples)).

There is more functionality available: see the `inotify(7)` man page
for more details, and of course the documentation in `inotify.py`
itself.

Lawrence D'Oliveiro <ldo@geek-central.gen.nz>
2018 March 11


Metadata

Release files for inotipy 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for inotipy 0.1.1
File Interpreter ABI Platform
inotipy-0.1.1-py3-none-any.whl Python 3 none any Details

Release files / inotipy-0.1.1-py3-none-any.whl

Download URL inotipy-0.1.1-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
825a26cd669047f49f56ce708bbe3b04b662710bce54cdf29a76f3a0ad40c988
BLAKE2b-256 checksum
How to use checksums
f80dc5ab325342bcc9fccf65a4619ded6c15db44b2292cada703afe7e9ccaa28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page