Skip to main content

Eventloop uses any of: pyuv or PySide2 or PyQt5 installed in the system to provide callback interface for filesystem events. And also timers.

Package intended to be a building block for utility scripts for recompiling or pushing files or restarting tests.

pyuv is used preferably as it’s most efficient. uv is a library that powers nodejs event loop.

Installing

eventloop can be installed via pip as follows:

pip install eventloop

Author

Stanislav Doronin <mugisbrows@gmail.com>

Usage

In simple case you can use on_file_changed decorator. It creates event loop, system watch and schedule, then connects them, then starts the loop and calls decorated function on filesystem events.

from eventloop import on_file_changed

if __name__ == "__main__":
    @on_file_changed("/path/to/dir")
    def your_handler(file_path):
        print(file_path)

Decorator accepts include and exclude args (list of globs or names to include or exclude files from watch) and timeout arg (read about timeout below) and loop arg.

If you need to watch more than one path you need to create and start EventLoop explicitly and pass it to decorators.

from eventloop import EventLoop, on_file_changed

if __name__ == "__main__":

    loop = EventLoop()

    @on_file_changed("/path/to/first/dir", loop=loop)
    def first_handler(file_path):
        print(file_path)

    @on_file_changed("/path/to/second/dir", loop=loop)
    def second_handler(file_path):
        print(file_path)

    loop.start()

For finer control over things you can use classes, first example can be rewriten as

from eventloop import EventLoop, FileSystemWatch, Schedule, base

class Executor(base.Executor):
    def execute(self, file_path):
        print(file_path)

if __name__ == "__main__":

    loop = EventLoop()
    executor = Executor()
    schedule = Schedule(executor)

    def on_change(file_path, event):
        schedule.append(file_path, timeout=1)

    watch = FileSystemWatch(loop)
    watch.start("/path/to/dir", on_change)
    loop.start()

Schedule caches (deduplicates) tasks appended within timeout interval, so for example three immediate consecutive changed events on same file end up in just one Executor.execute(task) call. on_file_changed decorator also uses Schedule to cache events.

Cli

You can use onchange script in command line to execute commands

python -m eventloop.onchange D:\dev\app -- echo FILE
onchange D:\dev\app -- echo FILE
onchange D:\dev\app -i *.cpp *.ui --cwd D:\dev\app\build -- ninja "&&" ctest
onchange . -i "*.pyx" --beep -- python setup.py build_ext --inplace
onchange http-server.py --server -- python -u http-server.py

License

Eventloop is distributed under the terms of MIT license, check LICENSE file.

Metadata

Release files for eventloop 0.0.26

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

Source distribution (sdist)

Source distribution for eventloop 0.0.26
File Size Uploaded Provenance
eventloop-0.0.26.tar.gz 11.9 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 26.9 kB

Release files / eventloop-0.0.26.tar.gz

Download URL eventloop-0.0.26.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
25f9d4fc8fe30df912597c9768cdb61fca11a85f1e0b78f0118132f412352a83
BLAKE2b-256 checksum
How to use checksums
ba89d1a22f5d4cf8bf7dbb7cbf91f1be563246679a7a6033d66b41baabf97b6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.1

Release files / eventloop-0.0.26-py3-none-any.whl

Download URL eventloop-0.0.26-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b64b1d88ddb5579ded9f6188e17747ca0b57d540a4336e3b925d27f7b0af3d9
BLAKE2b-256 checksum
How to use checksums
a812c037f96fb45ab2b2d563f717780f9f88ba5092cc51ca4b43e7c571ae978a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.1

Security for eventloop 0.0.26

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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