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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file aiowatcher-0.0.4.tar.gz.

File metadata

  • Download URL: aiowatcher-0.0.4.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for aiowatcher-0.0.4.tar.gz
Algorithm Hash digest
SHA256 3aea83ef6ecfacf428c8b57c23d54396eda604b7ebb8b975302edc0528fb4855
MD5 1afc4a14bc7c08914b6a953303d91608
BLAKE2b-256 d647fa2b0816aa3bf5cd7c60599fcfee7f30985d952c74c9506ba4aa1c9eb25f

See more details on using hashes here.

File details

Details for the file aiowatcher-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: aiowatcher-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for aiowatcher-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f9202c461c3478637c192ea7e7ed15622da25ad140993b6b7f4f54028d14ae37
MD5 bc5830120aa98770ab8a4f9f1320bc23
BLAKE2b-256 abc659fd8e1ffbe63ca110ee83c82942da8f9dd5275cb184068199e499808fe6

See more details on using hashes here.

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