Simple Linux inotify bindings for Python, including OSErrors.
Project description
panzi-inotify
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_INOTIFYFalseand only if you try to create an instance ofInotifyyou 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()andread_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
stopfdtoPollInotify(). This file descriptor will be added to theepoll_wait()call inPollInotify.wait(). IfPOLLINsignals for that thenwait()will returnFalse. 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,PermissionErroretc. andOSErroras 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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file panzi_inotify-1.0.2.tar.gz.
File metadata
- Download URL: panzi_inotify-1.0.2.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c603d0722708aa1a3aaa8ec1b9404abdedc99393b14c62d70f88f07fe72e6ca3
|
|
| MD5 |
df04f3d82eed94b8ec2edf6b0362ddb3
|
|
| BLAKE2b-256 |
d4b65fe0e5aea23c7a69f9ed82692db75883052d4add62326758bd919c5acacc
|
File details
Details for the file panzi_inotify-1.0.2-py3-none-any.whl.
File metadata
- Download URL: panzi_inotify-1.0.2-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cfe7d5bf2afe54761598eb3b474bb70d96b8649a45e84db9e93c1e5f2c76f05
|
|
| MD5 |
a12c00067cf3a735f943a2b5e330762e
|
|
| BLAKE2b-256 |
25da415942b44b46a7c75e78557897f5bfb08788e28a77f69151fa15d5ea218c
|