Skip to main content

panzi-inotify

Test Status Release Mozilla Public License Version 2.0 API Reference

Simple inotify bindings for Python.

I didn't like all the other available inotify bindings for one reason or anther. This one is different in these ways:

  • You can import the module even if your libc doesn't support inotify. It then will have HAS_INOTIFY False and only if you try to create an instance of Inotify you will get an exception (OSError(ENOSYS)).
  • It correctly handles paths that are invalid UTF-8 by using os.fsencode()/os.fsdecode() which use the 'surrogateescape' Unicode error handling option. This makes the file paths rountrip safe.
  • wait() and read_events() is separate. You can do your own wait/poll logic if you want.
  • You can use non-blocking mode and then read_events() only reads the available events. If there are none at the moment it returns an empty array.
  • You can pass a stopfd to PollInotify(). This file descriptor will be added to the epoll_wait() call in PollInotify.wait(). If POLLIN signals for that then wait() will return False. This is meant for implementing a way to stop a thread that waits for events without a timeout.
  • Translates errors to the appropriate Python exceptions from the given errno (FileNotFoundError, PermissionError etc. and OSError as fallback).
  • Uses Mozilla Public License Version 2.0, so you can use it from proprietary code, yet it isn't as permissive as MIT or BSD.

Installation

Via pip:

$ pip install panzi-inotify

Form source:

$ git clone git@github.com:panzi/panzi-inotify.git
$ pip install ./panzi-inotify

Example

from panzi_inotify import Inotify, get_inotify_event_names

import sys

with Inotify() as inotify:
    for filename in sys.argv[1:]:
        inotify.add_watch(filename)

    for event in inotify:
        print(f'{event.full_path()}: {", ".join(get_inotify_event_names(event.mask))}')

See examples for more.

You can also run a basic command line too to listen for events on a set of paths like this:

python -m panzi_inotify [--mask=MASK] <path>...

For more on this see:

python -m panzi_inotify --help

See Also

inotify(7)

Release files for panzi_inotify 1.0.3

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

Source distribution (sdist)

Source distribution for panzi_inotify 1.0.3
File Size Uploaded
panzi_inotify-1.0.3.tar.gz 17.9 kB Details

Built distribution (wheel)

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

Total release size: 35.0 kB

Release files / panzi_inotify-1.0.3.tar.gz

Download URL panzi_inotify-1.0.3.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cfdccb26b02ec4af0a6413138d83a52e6360c51751dea7422e0da44ac6f8cb3f
BLAKE2b-256 checksum
How to use checksums
84790395526ac8d465e7eb48cf4a334a0a6fe4f9a8f95be7f0b8ac91629fcb25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.5

Release files / panzi_inotify-1.0.3-py3-none-any.whl

Download URL panzi_inotify-1.0.3-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
206629eef0399d815df4fe1dbc7b3d0df9aebbbd0f5d89260cc9be1df29a30b8
BLAKE2b-256 checksum
How to use checksums
862f108d329457b5afed1b1c4305858cfabd82205e9d8677049f0682b0341d6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.5

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

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