larzwatch
Portable, poll-based file & directory watching. Pure Python, zero dependencies.
Detect when files are created, modified, or deleted, and react. It works by
comparing snapshots of modification times, so it has no native dependencies and
behaves identically on every OS (where watchdog needs platform backends). Run
a blocking loop, a background thread, or - crucially for tests - call poll()
yourself and inspect the changes.
from larzwatch import Watcher
w = Watcher("src", patterns=["*.py"])
w.on_change(lambda c: print(c.type, c.path)) # 'created' / 'modified' / 'deleted'
w.watch(interval=1) # blocking; or w.start() for a background thread
Why
- No native backends.
watchdogis great but ships OS-specific extensions; larzwatch is pure Python and works the same everywhere - handy for CI, weird filesystems, and locked-down environments. Polling is perfectly fine for reload-on-change, build triggers, and config reloading. - Testable.
poll()returns the exact list ofChange(type, path)since the last call, so you unit-test file-change logic without threads or sleeps. - Filtered & recursive.
patterns=["*.py", "*.toml"]andrecursive=True/False. - Zero dependencies.
Install
pip install larzwatch
Usage
from larzwatch import Watcher
w = Watcher("config", patterns=["*.yaml"])
w.on_change(reload_config)
# blocking loop
w.watch(interval=0.5)
# or background + your own loop
w.start(interval=0.5)
...
w.stop()
# or drive it yourself (tests, cron)
for change in w.poll():
print(change.type, change.path)
Tests
python -m unittest discover -s tests -v # 9 tests incl. create/modify/delete + background
The Larz stack
One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.
License
MIT (c) larz-scripter
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 larzwatch-0.1.0.tar.gz.
File metadata
- Download URL: larzwatch-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f1b3cde4ed5e5dc586d720136e1a379fb83619817da5d07fef9ed3e63020510
|
|
| MD5 |
db5972582bd4215b7f79044d0260516b
|
|
| BLAKE2b-256 |
95895cbaad10abbea00215803443efc5381d085b07f81789b815b8ebcc03adbe
|
File details
Details for the file larzwatch-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larzwatch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06d74d44b5a0e01cd8993d29c700c9b42a00c88ebb8634a3416aff3a449a325e
|
|
| MD5 |
2c0cd98d6d2d1eb08665c37a10541088
|
|
| BLAKE2b-256 |
e220b4788e5edc2af1a98e7be7a9f86f0ac928c0fbf86d699db900ebb8f8735d
|