Name | inotify-simple JSON |
Version |
2.0.1
JSON |
| download |
home_page | None |
Summary | A simple wrapper around inotify. No fancy bells and whistles, just a literal wrapper with ctypes. Under 100 lines of code! |
upload_time | 2025-08-25 06:28:20 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.6 |
license | None |
keywords |
inotify
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# inotify-simple 2.0
`inotify-simple` is a simple Python wrapper around
[inotify](http://man7.org/linux/man-pages/man7/inotify.7.html). 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](http://pypi.python.org/pypi/inotify-simple) |
[View on GitHub](https://github.com/chrisjbillington/inotify_simple) |
[Read the docs](http://inotify-simple.readthedocs.io)
## 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:
```bash
$ pip install inotify-simple
```
or to install from source, clone this repository and run:
```bash
$ pip install .
```
## Introduction
There are many inotify python wrappers out there. [I found them all
unsatisfactory](https://xkcd.com/927/). 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
```python
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](http://inotify-simple.readthedocs.io) for more.
Raw data
{
"_id": null,
"home_page": null,
"name": "inotify-simple",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "inotify",
"author": null,
"author_email": "Chris Billington <chrisjbillington@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/e3/5c/bfe40e15d684bc30b0073aa97c39be410a5fbef3d33cad6f0bf2012571e0/inotify_simple-2.0.1.tar.gz",
"platform": null,
"description": "# inotify-simple 2.0\n\n`inotify-simple` is a simple Python wrapper around\n[inotify](http://man7.org/linux/man-pages/man7/inotify.7.html). No fancy bells and\nwhistles, just a literal wrapper with ctypes. Less than 100 lines of code!\n\n`inotify_init1()` is wrapped as a file-like object, `INotify()`, holding the inotify\nfile descriptor. `INotify().read()` reads available data from the file descriptor and\nreturns events as `namedtuple` objects after unpacking them with the `struct` module.\n`inotify_add_watch()` and `inotify_rm_watch()` are wrapped with no changes at all,\ntaking and returning watch descriptor integers that calling code is expected to keep\ntrack of itself, just as one would use `inotify` from C. Requires Python 3.6 or higher.\n\n[View on PyPI](http://pypi.python.org/pypi/inotify-simple) |\n[View on GitHub](https://github.com/chrisjbillington/inotify_simple) |\n[Read the docs](http://inotify-simple.readthedocs.io)\n\n## Project status: stable\n\nThis project does not require much maintenance\nto continue to to meet its goals. Do not panic if there\nhave been no commits in a long time, this is normal.\n\n## Installation\n\nto install `inotify-simple`, run:\n\n```bash\n$ pip install inotify-simple\n```\n\nor to install from source, clone this repository and run:\n\n```bash\n$ pip install .\n```\n\n## Introduction\n\nThere are many inotify python wrappers out there. [I found them all\nunsatisfactory](https://xkcd.com/927/). Most are far too high-level for my\ntastes, and the supposed convenience they provide actually limits one from\nusing inotify in ways other than those the author imagined. Others are C\nextensions, requiring compilation for different platforms and Python versions,\nrather than a pure python module using ctypes. This one is pretty low-level\nand really just does what inotify itself does and nothing more. So hopefully\nif I've written it right, it will remain functional well into the future with\nno changes, recompilation or attention on my part.\n\n## Example usage\n\n```python\nimport os\nfrom inotify_simple import INotify, flags\n\nos.mkdir('/tmp/inotify_test')\n\ninotify = INotify()\nwatch_flags = flags.CREATE | flags.DELETE | flags.MODIFY | flags.DELETE_SELF\nwd = inotify.add_watch('/tmp/inotify_test', watch_flags)\n\n# Now create, delete and modify some files in the directory being monitored:\nos.chdir('/tmp/inotify_test')\n# CREATE event for a directory:\nos.system('mkdir foo')\n# CREATE event for a file:\nos.system('echo hello > test.txt')\n# MODIFY event for the file:\nos.system('echo world >> test.txt')\n# DELETE event for the file\nos.system('rm test.txt')\n# DELETE event for the directory\nos.system('rmdir foo')\nos.chdir('/tmp')\n# DELETE_SELF on the original directory. # Also generates an IGNORED event\n# indicating the watch was removed.\nos.system('rmdir inotify_test')\n\n# And see the corresponding events:\nfor event in inotify.read():\n print(event)\n for flag in flags.from_mask(event.mask):\n print(' ' + str(flag))\n```\n\nThis outputs the following:\n```\nEvent(wd=1, mask=1073742080, cookie=0, name=u'foo')\n flags.CREATE\n flags.ISDIR\nEvent(wd=1, mask=256, cookie=0, name=u'test.txt')\n flags.CREATE\nEvent(wd=1, mask=2, cookie=0, name=u'test.txt')\n flags.MODIFY\nEvent(wd=1, mask=512, cookie=0, name=u'test.txt')\n flags.DELETE\nEvent(wd=1, mask=1073742336, cookie=0, name=u'foo')\n flags.DELETE\n flags.ISDIR\nEvent(wd=1, mask=1024, cookie=0, name=u'')\n flags.DELETE_SELF\nEvent(wd=1, mask=32768, cookie=0, name=u'')\n flags.IGNORED\n```\n\nNote that the flags, since they are defined with an `enum.IntEnum`, print as\nwhat they are called rather than their integer values. However they are still\njust integers and so can be bitwise-ANDed and ORed etc with masks etc. The\n`flags.from_mask()` method bitwise-ANDs a mask with all possible flags and\nreturns a list of matches. This is for convenience and useful for debugging\nwhich events are coming through, but performance critical code should\ngenerally bitwise-AND masks with flags of interest itself so as to not do\nunnecessary checks.\n\n[See here](http://inotify-simple.readthedocs.io) for more.\n",
"bugtrack_url": null,
"license": null,
"summary": "A simple wrapper around inotify. No fancy bells and whistles, just a literal wrapper with ctypes. Under 100 lines of code!",
"version": "2.0.1",
"project_urls": {
"Documentation": "http://inotify-simple.readthedocs.io/",
"Issues": "https://github.com/chrisjbillington/inotify_simple/issues",
"Repository": "https://github.com/chrisjbillington/inotify_simple.git"
},
"split_keywords": [
"inotify"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "e3868be1ac7e90f80b413e81f1e235148e8db771218886a2353392f02da01be3",
"md5": "7f142474fb8a9108dc3d733ca7237079",
"sha256": "e5da495f2064889f8e68b67f9358b0d102e03b783c2d42e5b8e132ab859a5d8a"
},
"downloads": -1,
"filename": "inotify_simple-2.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7f142474fb8a9108dc3d733ca7237079",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 7449,
"upload_time": "2025-08-25T06:28:19",
"upload_time_iso_8601": "2025-08-25T06:28:19.919804Z",
"url": "https://files.pythonhosted.org/packages/e3/86/8be1ac7e90f80b413e81f1e235148e8db771218886a2353392f02da01be3/inotify_simple-2.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "e35cbfe40e15d684bc30b0073aa97c39be410a5fbef3d33cad6f0bf2012571e0",
"md5": "943fcbf1a7c82465ec7eaa77b40eff06",
"sha256": "f010bbbd8283bd71a9f4eb2de94765804ede24bd47320b0e6ef4136e541cdc2c"
},
"downloads": -1,
"filename": "inotify_simple-2.0.1.tar.gz",
"has_sig": false,
"md5_digest": "943fcbf1a7c82465ec7eaa77b40eff06",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 7101,
"upload_time": "2025-08-25T06:28:20",
"upload_time_iso_8601": "2025-08-25T06:28:20.998530Z",
"url": "https://files.pythonhosted.org/packages/e3/5c/bfe40e15d684bc30b0073aa97c39be410a5fbef3d33cad6f0bf2012571e0/inotify_simple-2.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-25 06:28:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "chrisjbillington",
"github_project": "inotify_simple",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "inotify-simple"
}