Hachiko
An extremely simple asyncio-based wrapper around Watchdog.
pip install hachiko
Hachiko supports Python 3.6 and newer, and watchdog 2.1.6 and newer (including watchdog 7). CI tests that whole range.
Example usage
You need to subclass AIOEventHandler and either:
- Use it directly with a Watchdog
Observerobject, or; - Pass it to
AIOWatchdogand use it there.
import asyncio
from hachiko import AIOEventHandler, AIOWatchdog
WATCH_DIRECTORY = "/path/to/watch/directory/"
class MyEventHandler(AIOEventHandler):
"""Subclass of asyncio-compatible event handler."""
async def on_created(self, event):
print("Created:", event.src_path) # add your functionality here
async def on_deleted(self, event):
print("Deleted:", event.src_path) # add your functionality here
async def on_moved(self, event):
print("Moved:", event.src_path, "->", event.dest_path)
async def on_modified(self, event):
print("Modified:", event.src_path) # add your functionality here
async def watch_fs(watch_dir):
evh = MyEventHandler() # create handlers inside a running event loop
async with AIOWatchdog(watch_dir, event_handler=evh):
await asyncio.sleep(20) # events are handled while this runs
asyncio.run(watch_fs(WATCH_DIRECTORY))
On Python 3.6, which has no asyncio.run(), use
asyncio.get_event_loop().run_until_complete(watch_fs(WATCH_DIRECTORY)).
Create your handler while the event loop is running (as above), or pass the
loop explicitly with MyEventHandler(loop=loop).
Starting and stopping
async with AIOWatchdog(...) starts watching on entry and stops on exit, even
if the body raises. You can also manage it yourself:
watch.start()starts watching.await watch.astop()stops watching and waits for watchdog's thread to finish without blocking the event loop.watch.stop()does the same but blocks the event loop while it waits.
Watch options
AIOWatchdog(path, recursive=True, event_handler=None, observer=None, **options)
pathcan be a directory or, with watchdog 7+, a single file.- Any extra keyword
optionsare passed to watchdog'sObserver.schedule(), so you can use whatever your installed watchdog supports. If it doesn't support an option, you get aTypeError. Useful ones:event_filter=[FileCreatedEvent, FileDeletedEvent](watchdog 4+) only delivers those event classes, fromwatchdog.events.follow_symlink=True(watchdog 7+) follows symbolic links.
observerlets you supply your own watchdog observer, e.g.PollingObserver()for network filesystems. On macOS with watchdog 7+,FSEventsObserver(latency=0.5)(fromwatchdog.observers.fsevents) merges rapid repeated events into one.
Events
Override any of these coroutines. Each receives the watchdog event object.
| Handler | Called for | Notes |
|---|---|---|
on_any_event |
every event | Also called for event types hachiko doesn't know about yet |
on_created |
file or directory created | |
on_deleted |
file or directory deleted | |
on_modified |
file or directory modified | |
on_moved |
file or directory moved/renamed | event.dest_path is the new path |
on_closed |
file closed after writing | Linux only |
on_closed_no_write |
file closed without writing | Linux only, watchdog 5+ |
on_opened |
file opened | Linux only, watchdog 2.3+ |
on_attrib |
metadata changed (permissions, timestamps…) | watchdog 7+; older versions report these as on_modified |
Watchdog sometimes reports the same change more than once, so handlers should be safe to run repeatedly for the same path.
Metadata
Release files for hachiko 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hachiko-0.6.0.tar.gz | 8.7 kB | With provenance | Details for hachiko-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hachiko-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for hachiko-0.6.0-py3-none-any.whl |
Total release size: 14.2 kB
Release files / hachiko-0.6.0.tar.gz
| Download URL | hachiko-0.6.0.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
632888b4b763b18dd98fc9fc7a61fd4ef3c48b3f70efd2ee1492ec5ec0839288
|
|
BLAKE2b-256 checksum How to use checksums |
c47a4cff181bc73ff36e35356da4c25db65cf81ffc8ce82828e8f71664a5a7b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logRelease files / hachiko-0.6.0-py3-none-any.whl
| Download URL | hachiko-0.6.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c5a5eb950d61de0bac729ea15c477794788a6a71fdb052a017cb22d96a9b05d
|
|
BLAKE2b-256 checksum How to use checksums |
156dac381d09467d8cb20ab04fd5cfc9552c9ef84e7e7450860deda63e722c6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logSecurity for hachiko 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for hachiko-0.6.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.