Skip to main content

Filesystem event watcher with decorator-based callbacks

Project description

philiprehberger-file-watcher

Tests PyPI version GitHub release Last updated License Bug Reports Feature Requests Sponsor

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 package useful, consider giving it a star on GitHub — it helps motivate continued maintenance and development.

LinkedIn More packages

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_file_watcher-0.2.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_file_watcher-0.2.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_file_watcher-0.2.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_file_watcher-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ded6c07cb6fdc98c95e64034dafeba137fc264e74142ce921d7f4276b91c2401
MD5 4da169533891f1f6f3df4983778d8f7c
BLAKE2b-256 b82b3fec1072cba9e54a5c3a850618d47a304cc038b084bc2b828cece42db81b

See more details on using hashes here.

File details

Details for the file philiprehberger_file_watcher-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_file_watcher-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b262e3e375eb827157b966bfa6b59d5f3c0e150baf2aec06088d4acdab8228c0
MD5 dcd6450f9b3d25cb49bb483559b990d0
BLAKE2b-256 bc599a195d9622672ab08a6d67c516d188c2fbca75e5b78d51f13fde3eced640

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page