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

Uploaded Source

Built Distribution

aiowatcher-0.0.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiowatcher-0.0.2.tar.gz
  • Upload date:
  • Size: 5.0 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.2.tar.gz
Algorithm Hash digest
SHA256 00890319530c2c9bb2df4899faf1c2eb7687f1f1771f492e082b595d05297c6f
MD5 ff7c503402f37ebc2e3c92fa5c483f65
BLAKE2b-256 48eed5bb3d74fa1cdec1ab856dd9c568972663e914c03d743224363625abe855

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiowatcher-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4e7bfcc2ff4dc4d0faa107340540ed9c2c6f0b569a3f1169ace50c5d38219a35
MD5 769d85ef9ead7704377284a121fdf42b
BLAKE2b-256 fec4427e53ddaad982a0b790d3b9c2fde4aaa32a0f5d1d01675c2bb0958e7760

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