docs: add more real-world example scripts
Description
Following our efforts to improve the documentation and the introduction of the new Examples page, we want to expand our gallery of practical, real-world watchdog configurations.
We would like to invite first-time contributors to add clean, executable example Python scripts for common use cases.
How to contribute:
Choose/Propose a Use Case:
Add a Python script: Create a new Python script under
docs/source/examples/(e.g.docs/source/examples/renaming.py). Make sure it is self-contained and clean.Link to the docs: Open
docs/source/examples.rstand include your script using theliteralincludedirective:.. literalinclude:: examples/renaming.py :language: python :linenos:Register in tests: Open tests/test_examples.py and add your example script name to the list of tested files so that it gets automatically tested in CI/CD.
Open a PR!
Suggested Example Ideas for Contributors:
Here are some high-value real-world examples currently missing from our docs:
- Multi-Directory Monitoring: Monitoring multiple distinct directories with a single
Observerand labeled handlers. (PR #1269 by @hugosmoreira) - Context Manager (
with Observer()): Demonstrating modern Pythonwithstatement syntax for automatic start/stop observer lifecycle.(PR #1267 by @Kiveiru3) - Auto-Restart / Live-Reload: Automatically restarting a script or subprocess when monitored source files change.(PR #1268 by @Dheekshi-07)
- Asyncio / Event Loop Integration: Bridging watchdog filesystem events into an
asyncioevent loop.(PR #1273 by @subikshajegadish) -
AutoRestartTrickExample: Automatically restarting a long-running subprocess (e.g. web server or worker) when monitored source files change. -
ShellCommandTrickExample: Executing automated build/test commands (like runningpytestor a linter) when files are created/modified.(PR #1270 by @Larslllllll) - Custom
TrickSubclass: Building a reusable, pattern-matchedTrickthat works programmatically and viawatchmedo tricks.yaml.(PR #1272 by @MOHAMEDB999) - Event Batching / Coalescing: Using a background worker queue or debounce pattern to process filesystem events in batches.
When opening your PR, please include:
Contributes to #1190 (Multi-Directory Monitoring Example)
(Please ensure to review our Examples Documentation and existing scripts in docs/source/examples/ before proposing. If you have a novel use case that is not listed above or already covered, feel free to propose it by commenting below or opening a draft PR to discuss!)
Source: gorakhargosh/watchdog