Filesystem event watcher with decorator-based callbacks
Project description
philiprehberger-file-watcher
Filesystem event watcher with decorator-based callbacks.
Installation
pip install philiprehberger-file-watcher
Usage
Basic Watching
from philiprehberger_file_watcher import Watcher
watcher = Watcher("./src")
@watcher.on("created", pattern="*.py")
def on_new_python_file(event):
print(f"New file: {event.path}")
@watcher.on("modified", pattern="*.css")
def on_css_change(event):
print(f"CSS changed: {event.path}")
@watcher.on("any")
def on_anything(event):
print(f"{event.type}: {event.path}")
# Blocking
watcher.start()
# Or background mode
watcher.start(background=True)
# ... do other work ...
watcher.stop()
Batch Event Collection
watcher = Watcher("./uploads")
def handle_batch(events):
print(f"Received {len(events)} files at once")
for event in events:
print(f" {event.path}")
# Fire callback when 50 events collected or after 3 seconds
watcher.on_batch("created", handle_batch, batch_size=50, timeout=3.0)
watcher.start(background=True)
Event Types
"created", "modified", "deleted", "moved", "any"
API
| Function / Class | Description |
|---|---|
Watcher(path, recursive, debounce) |
Watch a directory for filesystem changes with decorator-based event handlers |
FileEvent |
A filesystem event with type, path, is_directory, and dest_path fields |
Watcher.on(event_type, pattern) |
Decorator to register a single-event callback |
Watcher.add_listener(event_type, callback, pattern) |
Programmatically add an event listener |
Watcher.on_batch(event_type, callback, batch_size, timeout) |
Register a batch callback that fires on size or timeout |
Watcher.start(background) |
Start watching (blocking or background) |
Watcher.stop() |
Stop watching |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Project details
Release history Release notifications | RSS feed
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 philiprehberger_file_watcher-0.2.1.tar.gz.
File metadata
- Download URL: philiprehberger_file_watcher-0.2.1.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb3691005fe1d995ec53a3056092ddde310e9e6c6d888c3b0b64e5cc8b89c1c2
|
|
| MD5 |
06d060819836da155fd26da18663da40
|
|
| BLAKE2b-256 |
bc399f804416f6755d4f2fd40a81485dc27bea4319c94166ea1f200bf6c47ccf
|
File details
Details for the file philiprehberger_file_watcher-0.2.1-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_file_watcher-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cae2c0eb31c2e7e4728240655fab95623c2451c65b13e7ede1dfb00b6bdfc6de
|
|
| MD5 |
790f227f24f079e92939921e709a86a3
|
|
| BLAKE2b-256 |
6591fd2b30758bb53073672eba3920e5488699b58705863af7ba586fce478bd0
|