Skip to main content

Asynchronous library to watch files in real time.

Project description

AIOWatcher

aiowatcher logo

GitHub repo size PyPI PyPI - Wheel GitHub GitHub last commit

Library to “watch” files in a directory and call a callback function (filename, lines) every time one of the monitored files is recorded, in real time.

In practical terms, this can be compared to UNIX’s tail -F * .log command, but instead of having lines printed in stdout, a Python function is called.

Like tail, it is in charge of “watching” new files that are created after startup and “unlock” those that are removed in the meantime. This means that you will be able to “follow” and support rotating log files as well.

Key Features

  • Uses Asyncio for asynchronous reading and monitoring.

  • The implementation chooses automatically depending on the compatibility of the system.

  • Monitoring of several files in the same directory or just one.

  • Asynchronous callback function.

Getting started

All code samples require Python 3.6+.

Basic Usage

import asyncio
from aiowatcher import AIOWatcher

async def callback(filename, line):
    print(line)

async def main():
    lw = AIOWatcher('var', callback, extensions=['txt'])
    await lw.init()
    await lw.loop()

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Non blocking

import asyncio
from aiowatcher import AIOWatcher

async def callback(filename, line):
    print(line)

async def main():
    lw = AIOWatcher('var', callback, extensions=['txt'])
    while True:
        await lw.loop(blocking=False)
        await asyncio.sleep(0.1)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

License

aiowatcher is offered under the Apache 2 license.

Source code

The latest version of the developer is available on a GitHub repository: https://github.com/py-paulo/aiowatcher.git

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiowatcher-0.0.4.tar.gz (5.8 kB view hashes)

Uploaded Source

Built Distribution

aiowatcher-0.0.4-py3-none-any.whl (10.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page