Skip to main content

AIOWatcher logo

GitHub code size in bytes PyPI PyPI - Wheel GitHub last commit
GitHub


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

Tail

import asyncio
from aiowatcher import AIOWatcher

async def callback(filename, lines):
    for line in lines:
        print(line[:-1])

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

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

Changelog

0.0.5 (22-09-2020)

Features

  • new AIOWatcher().tail function to read N lines from a file and return as list.

Bugfixes

  • AIOWatcher.readlines() returns a list instead of a string.

Release files for aiowatcher 0.0.5

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

Source distribution (sdist)

Source distribution for aiowatcher 0.0.5
File Size Uploaded
aiowatcher-0.0.5.tar.gz 6.3 kB Details

Built distribution (wheel)

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

Total release size: 16.8 kB

Release files / aiowatcher-0.0.5.tar.gz

Download URL aiowatcher-0.0.5.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
913e0fa9b7380935a37aa31fb2ea87f4f38ed41d39cd818e8dcefc22b707ba69
BLAKE2b-256 checksum
How to use checksums
5ed9d531a214c3087e39b53fd331d5623595e90f2774feac561af459b2eda57c
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / aiowatcher-0.0.5-py3-none-any.whl

Download URL aiowatcher-0.0.5-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c9ca961daf12812c4fb07eb0f8c2f512862b3b2c35352c6cd8ef71adfb38ad6
BLAKE2b-256 checksum
How to use checksums
320f6c64bb8deeff56f699d032a598665c965550b1968d76bea305630ccbcd53
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

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