Skip to main content
Watch filesystem for real-time changes. Get notified immediately when files are created, modified, deleted, or renamed in your sandbox.

Overview

File watching is perfect for:
  • Real-time monitoring of file changes
  • Building reactive applications
  • Detecting when outputs are generated
  • Implementing file-based workflows
File watching uses WebSocket connections for real-time communication. It requires async/await support and the websockets library (Python).

Basic File Watching

Watch a directory for changes:

Event Types

Handle different file system events:

Monitoring File Generation

Watch for generated output files:

Filtering Events

Filter events by type or path:

Complete Example

Here’s a complete file watching workflow:

Best Practices

1

1. Use Async/Await

File watching requires async/await. Make sure your code uses async functions and async for loops.
2

2. Filter Events

Filter events by type or path pattern to process only relevant changes.
3

3. Handle All Event Types

Process created, modified, deleted, and renamed events appropriately for your use case.
4

4. Set Timeout Limits

Consider setting timeouts or event count limits to avoid infinite watching.
5

5. Clean Up Connections

Always break the watch loop and clean up connections when done.

Next Steps