Skip to main content

Asynchronous library to watch files in real time.

Project description

https://img.shields.io/github/languages/code-size/py-paulo/aiowatcher:alt:GitHubcodesizeinbytes https://img.shields.io/github/license/py-paulo/aiowatcher:alt:GitHub

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

Practically speaking, this can be compared to tail -F *.log UNIX command, but instead of having lines printed to stdout a python function gets called.

Similarly to tail, it takes care of “watching” new files which are created after initialization and “unwatching” those ones which are removed in the meantime. This means you’ll be able to “follow” and support also rotating log files.

Code examples

All code examples requires 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())

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.2.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

aiowatcher-0.0.2-py3-none-any.whl (9.5 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