Skip to main content

Simple Linux inotify bindings for Python, including OSErrors.

Project description

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)

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

panzi_inotify-1.0.3.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

panzi_inotify-1.0.3-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file panzi_inotify-1.0.3.tar.gz.

File metadata

  • Download URL: panzi_inotify-1.0.3.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for panzi_inotify-1.0.3.tar.gz
Algorithm Hash digest
SHA256 cfdccb26b02ec4af0a6413138d83a52e6360c51751dea7422e0da44ac6f8cb3f
MD5 a4496cce62d2159c438bd5cfce2908a1
BLAKE2b-256 84790395526ac8d465e7eb48cf4a334a0a6fe4f9a8f95be7f0b8ac91629fcb25

See more details on using hashes here.

File details

Details for the file panzi_inotify-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for panzi_inotify-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 206629eef0399d815df4fe1dbc7b3d0df9aebbbd0f5d89260cc9be1df29a30b8
MD5 1787f2acecc00919b12f733d5b17a445
BLAKE2b-256 862f108d329457b5afed1b1c4305858cfabd82205e9d8677049f0682b0341d6d

See more details on using hashes here.

Supported by

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