← Back to all products

File Watcher

$19

File system watcher monitoring directories for changes with glob pattern matching and configurable actions.

📁 9 files
JSONMarkdownPython

📄 Product Preview

Try the interactive reader and demo tools below, or get the full product with all content unlocked.

📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample

📁 File Structure 9 files

file-watcher/ ├── LICENSE ├── README.md ├── examples/ │ └── watcher_config.json ├── free-sample.zip ├── guide/ │ ├── 01_features.md │ ├── 02_quick-start.md │ └── 03_faq.md ├── index.html └── src/ └── file_watcher.py

📖 Documentation Preview README excerpt

File Watcher

A file system watcher that monitors directories for changes and triggers configurable actions. Supports glob pattern matching, recursive watching, debouncing, and multiple action types: shell commands, HTTP webhooks, and structured log entries.

Features

  • Directory monitoring — Poll-based filesystem watching (works on any OS)
  • Glob pattern matching — Watch only .py, .csv, data/*.json, etc.
  • Recursive watching — Monitor subdirectories automatically
  • Debouncing — Configurable delay to batch rapid changes into single events
  • Shell command triggers — Run any command on file change
  • Webhook triggers — POST change events to any HTTP endpoint
  • Log triggers — Structured log entries for audit trails
  • Checksum detection — Optional MD5 checksums for content-aware change detection
  • Multi-rule support — Watch different directories with different patterns and actions
  • Event history — SQLite log of all detected changes

Requirements

  • Python 3.10+
  • No external dependencies (stdlib only)

Quick Start


# Watch a directory and run tests on Python file changes
python src/file_watcher.py --watch ./src --pattern "*.py" --command "python -m pytest"

# Watch for CSV changes and hit a webhook
python src/file_watcher.py --watch ./data --pattern "*.csv" \
    --webhook https://api.example.com/v1/reload

# Use a config file for complex setups
python src/file_watcher.py --config examples/watcher_config.json

# Watch with content-aware checksums (detects real content changes, not just timestamps)
python src/file_watcher.py --watch ./src --pattern "*.py" --checksums --command "make build"

Configuration Reference


{
    "rules": [
        {
            "name": "python-tests",
            "watch_path": "./src",
            "patterns": ["*.py"],
            "recursive": true,
            "actions": [
                {"type": "command", "command": "python -m pytest tests/"},
                {"type": "log"}
            ]
        },
        {
            "name": "data-reload",
            "watch_path": "./data",
            "patterns": ["*.csv", "*.json"],
            "recursive": false,
            "actions": [

*... continues with setup instructions, usage examples, and more.*

📄 Code Sample .py preview

src/file_watcher.py #!/usr/bin/env python3 """ File Watcher — Automation Hub (DataNest) A file system watcher that monitors directories for changes and triggers configurable actions. Supports glob pattern matching, recursive watching, debouncing, and action triggers (shell commands, HTTP webhooks, log entries). Usage: python file_watcher.py --watch ./src --pattern "*.py" --command "python -m pytest" python file_watcher.py --config watcher_config.json python file_watcher.py --watch ./data --pattern "*.csv" --webhook https://api.example.com/v1/reload Dependencies: Python 3.10+ stdlib only (no pip packages) License: MIT """ from __future__ import annotations import argparse import fnmatch import hashlib import json import logging import os import signal import sqlite3 import subprocess import threading import time import urllib.request from dataclasses import dataclass, field from datetime import datetime, timezone from enum import Enum from pathlib import Path from typing import Any, Callable # --------------------------------------------------------------------------- # Constants # --------------------------------------------------------------------------- LOG_FORMAT = "%(asctime)s [%(levelname)s] %(name)s: %(message)s" DEFAULT_POLL_INTERVAL = 2.0 # seconds between filesystem scans DEFAULT_DEBOUNCE = 0.5 # seconds to wait before triggering after a change logger = logging.getLogger("file_watcher") # --------------------------------------------------------------------------- # Enums & data models # ... 571 more lines ...
Buy Now — $19 Back to Products