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)
Stopping watches and introspection
watcher = Watcher("./src")
watcher.start(background=True)
# Inspect currently-watched paths
print(watcher.watched_paths()) # ['/abs/path/to/src']
# Stop watching a specific path
removed = watcher.unwatch("./src") # True if the path was being watched
print(watcher.watched_paths()) # []
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 |
Watcher.unwatch(path) |
Stop watching a specific path; returns True if the path was being watched |
Watcher.watched_paths() |
Return a snapshot list of currently-watched paths |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Metadata
Release files for philiprehberger-file-watcher 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| philiprehberger_file_watcher-0.3.0.tar.gz | 181.5 kB | Without provenance | Details for philiprehberger_file_watcher-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| philiprehberger_file_watcher-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for philiprehberger_file_watcher-0.3.0-py3-none-any.whl |
Total release size: 187.4 kB
Release files / philiprehberger_file_watcher-0.3.0.tar.gz
| Download URL | philiprehberger_file_watcher-0.3.0.tar.gz |
|---|---|
| Size | 181.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9348bf6afc42c9acc6918c4909f08afd98259a4b1580f512c968b82d05b1473
|
|
BLAKE2b-256 checksum How to use checksums |
f97a732749b154f4c84562e9c4e7b868b415c2a2f6047b49b5dec53c6ffbe490
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / philiprehberger_file_watcher-0.3.0-py3-none-any.whl
| Download URL | philiprehberger_file_watcher-0.3.0-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da7a4ef584065a64ba89d9e31e2ea0dda6f529696a1cbb611330350058d1ad6e
|
|
BLAKE2b-256 checksum How to use checksums |
8d8b5a81b4969a8799286f6121d6d9128ea9d0a7162ad3334e94b56d8fd327d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for philiprehberger-file-watcher 0.3.0
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.