Skip to main content

Hachiko

CI PyPI

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.

Hachiko includes type hints, so type checkers such as mypy check your handlers against its API.

Example usage

You need to subclass AIOEventHandler and either:

  1. Use it directly with a Watchdog Observer object, or;
  2. Pass it to AIOWatchdog and 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)

  • path can be a directory or, with watchdog 7+, a single file.
  • Any extra keyword options are passed to watchdog's Observer.schedule(), so you can use whatever your installed watchdog supports. If it doesn't support an option, you get a TypeError. Useful ones:
    • event_filter=[FileCreatedEvent, FileDeletedEvent] (watchdog 4+) only delivers those event classes, from watchdog.events.
    • follow_symlink=True (watchdog 7+) follows symbolic links.
  • observer lets you supply your own watchdog observer, e.g. PollingObserver() for network filesystems. On macOS with watchdog 7+, FSEventsObserver(latency=0.5) (from watchdog.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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hachiko 0.6.1
File Size Uploaded Provenance Actions
hachiko-0.6.1.tar.gz 9.8 kB With provenance Details for hachiko-0.6.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hachiko 0.6.1
File Interpreter ABI Platform Actions
hachiko-0.6.1-py3-none-any.whl Python 3 none any Details for hachiko-0.6.1-py3-none-any.whl

Total release size: 15.9 kB

Release files / hachiko-0.6.1.tar.gz

Download URL hachiko-0.6.1.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
843683cde815b18c9ad290d135ce8fcbf4da63605cd885bf5aba8ec0f42e5992
BLAKE2b-256 checksum
How to use checksums
5a303fd427e82783a8cf64db46e7fa140f6bff2fcbfd287477b04877343e03d3
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 log

Release files / hachiko-0.6.1-py3-none-any.whl

Download URL hachiko-0.6.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9849be10dc22787ae42fdc8735777280ce4f40d00de337e9e6f2d425f99d06ed
BLAKE2b-256 checksum
How to use checksums
5bee6878d45e3e7034fb434dcf3794c9c88274e5b293c6423e7c4f2e55c590c8
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 log

Security for hachiko 0.6.1

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.

Select from 2 files

Attestation for hachiko-0.6.1.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 log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page