watchdog.events#
- module:
watchdog.events
- synopsis:
File system events and event handlers.
- author:
yesudeep@google.com (Yesudeep Mangalapilly)
- author:
Mickaël Schoentgen <contact@tiger-222.fr>
Event Classes#
- class watchdog.events.FileSystemEvent(src_path: bytes | str, dest_path: bytes | str = '', is_synthetic: bool = False)[source]#
Bases:
objectRepresents a file system event that is triggered when a change occurs on the monitored file system.
FileSystemEvent instances are mutable, so avoid using them as dictionary keys or set members: mutating an instance after insertion can silently break lookups.
- class watchdog.events.FileSystemMovedEvent(src_path: bytes | str, dest_path: bytes | str = '', is_synthetic: bool = False)[source]#
Bases:
FileSystemEventFile system event representing any kind of file system movement.
- class watchdog.events.FileMovedEvent(src_path: bytes | str, dest_path: bytes | str = '', is_synthetic: bool = False)[source]#
Bases:
FileSystemMovedEventFile system event representing file movement on the file system.
- class watchdog.events.DirMovedEvent(src_path: bytes | str, dest_path: bytes | str = '', is_synthetic: bool = False)[source]#
Bases:
FileSystemMovedEventFile system event representing directory movement on the file system.
- class watchdog.events.FileModifiedEvent(src_path: bytes | str, dest_path: bytes | str = '', is_synthetic: bool = False)[source]#
Bases:
FileSystemEventFile system event representing file modification on the file system.
- class watchdog.events.DirModifiedEvent(src_path: bytes | str, dest_path: bytes | str = '', is_synthetic: bool = False)[source]#
Bases:
FileSystemEventFile system event representing directory modification on the file system.
- class watchdog.events.FileCreatedEvent(src_path: bytes | str, dest_path: bytes | str = '', is_synthetic: bool = False)[source]#
Bases:
FileSystemEventFile system event representing file creation on the file system.
- class watchdog.events.FileClosedEvent(src_path: bytes | str, dest_path: bytes | str = '', is_synthetic: bool = False)[source]#
Bases:
FileSystemEventFile system event representing file close on the file system.
Emitted only by
InotifyObserveron Linux.
- class watchdog.events.FileClosedNoWriteEvent(src_path: bytes | str, dest_path: bytes | str = '', is_synthetic: bool = False)[source]#
Bases:
FileSystemEventFile system event representing an unmodified file close on the file system.
Emitted only by
InotifyObserveron Linux.
- class watchdog.events.FileOpenedEvent(src_path: bytes | str, dest_path: bytes | str = '', is_synthetic: bool = False)[source]#
Bases:
FileSystemEventFile system event representing file open on the file system.
Emitted only by
InotifyObserveron Linux.
- class watchdog.events.DirCreatedEvent(src_path: bytes | str, dest_path: bytes | str = '', is_synthetic: bool = False)[source]#
Bases:
FileSystemEventFile system event representing directory creation on the file system.
- class watchdog.events.FileDeletedEvent(src_path: bytes | str, dest_path: bytes | str = '', is_synthetic: bool = False)[source]#
Bases:
FileSystemEventFile system event representing file deletion on the file system.
Event Handler Classes#
- class watchdog.events.FileSystemEventHandler[source]#
Bases:
objectBase file system event handler that you can override methods from.
- dispatch(event: FileSystemEvent) None[source]#
Dispatches events to the appropriate methods.
- Parameters:
event (
watchdog.events.FileSystemEvent) – The event object representing the file system event.
- on_any_event(event: FileSystemEvent) None[source]#
Catch-all event handler.
- Parameters:
event (
watchdog.events.FileSystemEvent) – The event object representing the file system event.
- on_closed(event: FileClosedEvent) None[source]#
Called when a file opened for writing is closed.
Emitted only by
InotifyObserveron Linux.- Parameters:
event (
watchdog.events.FileClosedEvent) – Event representing file closing.
- on_closed_no_write(event: FileClosedNoWriteEvent) None[source]#
Called when a file opened for reading is closed.
Emitted only by
InotifyObserveron Linux.- Parameters:
event (
watchdog.events.FileClosedNoWriteEvent) – Event representing file closing.
- on_created(event: DirCreatedEvent | FileCreatedEvent) None[source]#
Called when a file or directory is created.
- Parameters:
event (
watchdog.events.DirCreatedEventorwatchdog.events.FileCreatedEvent) – Event representing file/directory creation.
- on_deleted(event: DirDeletedEvent | FileDeletedEvent) None[source]#
Called when a file or directory is deleted.
- Parameters:
event (
watchdog.events.DirDeletedEventorwatchdog.events.FileDeletedEvent) – Event representing file/directory deletion.
- on_modified(event: DirModifiedEvent | FileModifiedEvent) None[source]#
Called when a file or directory is modified.
- Parameters:
event (
watchdog.events.DirModifiedEventorwatchdog.events.FileModifiedEvent) – Event representing file/directory modification.
- on_moved(event: DirMovedEvent | FileMovedEvent) None[source]#
Called when a file or a directory is moved or renamed.
- Parameters:
event (
watchdog.events.DirMovedEventorwatchdog.events.FileMovedEvent) – Event representing file/directory movement.
- on_opened(event: FileOpenedEvent) None[source]#
Called when a file is opened.
Emitted only by
InotifyObserveron Linux.- Parameters:
event (
watchdog.events.FileOpenedEvent) – Event representing file opening.
- class watchdog.events.PatternMatchingEventHandler(*, patterns: list[str] | None = None, ignore_patterns: list[str] | None = None, ignore_directories: bool = False, case_sensitive: bool = False)[source]#
Bases:
FileSystemEventHandlerMatches given patterns with file paths associated with occurring events. Uses pathlib’s PurePath.match() method. patterns and ignore_patterns are expected to be a list of strings.
- property case_sensitive: bool#
(Read-only)
Trueif path names should be matched sensitive to case;Falseotherwise.
- dispatch(event: FileSystemEvent) None[source]#
Dispatches events to the appropriate methods.
- Parameters:
event (
watchdog.events.FileSystemEvent) – The event object representing the file system event.
- class watchdog.events.RegexMatchingEventHandler(*, regexes: list[str] | None = None, ignore_regexes: list[str] | None = None, ignore_directories: bool = False, case_sensitive: bool = False)[source]#
Bases:
FileSystemEventHandlerMatches given regexes with file paths associated with occurring events. Uses the re module.
- property case_sensitive: bool#
(Read-only)
Trueif path names should be matched sensitive to case;Falseotherwise.
- dispatch(event: FileSystemEvent) None[source]#
Dispatches events to the appropriate methods.
- Parameters:
event (
watchdog.events.FileSystemEvent) – The event object representing the file system event.
- class watchdog.events.LoggingEventHandler(*, logger: Logger | None = None)[source]#
Bases:
FileSystemEventHandlerLogs all the events captured.
- on_closed(event: FileClosedEvent) None[source]#
Called when a file opened for writing is closed.
Emitted only by
InotifyObserveron Linux.- Parameters:
event (
watchdog.events.FileClosedEvent) – Event representing file closing.
- on_closed_no_write(event: FileClosedNoWriteEvent) None[source]#
Called when a file opened for reading is closed.
Emitted only by
InotifyObserveron Linux.- Parameters:
event (
watchdog.events.FileClosedNoWriteEvent) – Event representing file closing.
- on_created(event: DirCreatedEvent | FileCreatedEvent) None[source]#
Called when a file or directory is created.
- Parameters:
event (
watchdog.events.DirCreatedEventorwatchdog.events.FileCreatedEvent) – Event representing file/directory creation.
- on_deleted(event: DirDeletedEvent | FileDeletedEvent) None[source]#
Called when a file or directory is deleted.
- Parameters:
event (
watchdog.events.DirDeletedEventorwatchdog.events.FileDeletedEvent) – Event representing file/directory deletion.
- on_modified(event: DirModifiedEvent | FileModifiedEvent) None[source]#
Called when a file or directory is modified.
- Parameters:
event (
watchdog.events.DirModifiedEventorwatchdog.events.FileModifiedEvent) – Event representing file/directory modification.
- on_moved(event: DirMovedEvent | FileMovedEvent) None[source]#
Called when a file or a directory is moved or renamed.
- Parameters:
event (
watchdog.events.DirMovedEventorwatchdog.events.FileMovedEvent) – Event representing file/directory movement.
- on_opened(event: FileOpenedEvent) None[source]#
Called when a file is opened.
Emitted only by
InotifyObserveron Linux.- Parameters:
event (
watchdog.events.FileOpenedEvent) – Event representing file opening.