Skip to main content

inotify-simple 2.0

inotify-simple is a simple Python wrapper around inotify. No fancy bells and whistles, just a literal wrapper with ctypes. Less than 100 lines of code!

inotify_init1() is wrapped as a file-like object, INotify(), holding the inotify file descriptor. INotify().read() reads available data from the file descriptor and returns events as namedtuple objects after unpacking them with the struct module. inotify_add_watch() and inotify_rm_watch() are wrapped with no changes at all, taking and returning watch descriptor integers that calling code is expected to keep track of itself, just as one would use inotify from C. Requires Python 3.6 or higher.

View on PyPI | View on GitHub | Read the docs

Project status: stable

This project does not require much maintenance to continue to to meet its goals. Do not panic if there have been no commits in a long time, this is normal.

Installation

to install inotify-simple, run:

$ pip install inotify-simple

or to install from source, clone this repository and run:

$ pip install .

Introduction

There are many inotify python wrappers out there. I found them all unsatisfactory. Most are far too high-level for my tastes, and the supposed convenience they provide actually limits one from using inotify in ways other than those the author imagined. Others are C extensions, requiring compilation for different platforms and Python versions, rather than a pure python module using ctypes. This one is pretty low-level and really just does what inotify itself does and nothing more. So hopefully if I've written it right, it will remain functional well into the future with no changes, recompilation or attention on my part.

Example usage

import os
from inotify_simple import INotify, flags

os.mkdir('/tmp/inotify_test')

inotify = INotify()
watch_flags = flags.CREATE | flags.DELETE | flags.MODIFY | flags.DELETE_SELF
wd = inotify.add_watch('/tmp/inotify_test', watch_flags)

# Now create, delete and modify some files in the directory being monitored:
os.chdir('/tmp/inotify_test')
# CREATE event for a directory:
os.system('mkdir foo')
# CREATE event for a file:
os.system('echo hello > test.txt')
# MODIFY event for the file:
os.system('echo world >> test.txt')
# DELETE event for the file
os.system('rm test.txt')
# DELETE event for the directory
os.system('rmdir foo')
os.chdir('/tmp')
# DELETE_SELF on the original directory. # Also generates an IGNORED event
# indicating the watch was removed.
os.system('rmdir inotify_test')

# And see the corresponding events:
for event in inotify.read():
    print(event)
    for flag in flags.from_mask(event.mask):
        print('    ' + str(flag))

This outputs the following:

Event(wd=1, mask=1073742080, cookie=0, name=u'foo')
    flags.CREATE
    flags.ISDIR
Event(wd=1, mask=256, cookie=0, name=u'test.txt')
    flags.CREATE
Event(wd=1, mask=2, cookie=0, name=u'test.txt')
    flags.MODIFY
Event(wd=1, mask=512, cookie=0, name=u'test.txt')
    flags.DELETE
Event(wd=1, mask=1073742336, cookie=0, name=u'foo')
    flags.DELETE
    flags.ISDIR
Event(wd=1, mask=1024, cookie=0, name=u'')
    flags.DELETE_SELF
Event(wd=1, mask=32768, cookie=0, name=u'')
    flags.IGNORED

Note that the flags, since they are defined with an enum.IntEnum, print as what they are called rather than their integer values. However they are still just integers and so can be bitwise-ANDed and ORed etc with masks etc. The flags.from_mask() method bitwise-ANDs a mask with all possible flags and returns a list of matches. This is for convenience and useful for debugging which events are coming through, but performance critical code should generally bitwise-AND masks with flags of interest itself so as to not do unnecessary checks.

See here for more.

Release files for inotify-simple 2.0.1

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

Source distribution (sdist)

Source distribution for inotify-simple 2.0.1
File Size Uploaded
inotify_simple-2.0.1.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for inotify-simple 2.0.1
File Interpreter ABI Platform
inotify_simple-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.6 kB

Release files / inotify_simple-2.0.1.tar.gz

Download URL inotify_simple-2.0.1.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f010bbbd8283bd71a9f4eb2de94765804ede24bd47320b0e6ef4136e541cdc2c
BLAKE2b-256 checksum
How to use checksums
e35cbfe40e15d684bc30b0073aa97c39be410a5fbef3d33cad6f0bf2012571e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2025.

Transparency log

Release files / inotify_simple-2.0.1-py3-none-any.whl

Download URL inotify_simple-2.0.1-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5da495f2064889f8e68b67f9358b0d102e03b783c2d42e5b8e132ab859a5d8a
BLAKE2b-256 checksum
How to use checksums
e3868be1ac7e90f80b413e81f1e235148e8db771218886a2353392f02da01be3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.3.5

1 release file

1.3.4

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.8

1 release file

1.1.7

1 release file

1.1.6

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.1

1 release file

1.1.0

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

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