Skip to content

Commit

Permalink
Documentation and example of the Python API
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Palard committed Aug 10, 2013
1 parent b0b5343 commit d347e0a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,3 +1,7 @@
2013-08-10 18:04:37 +0200 Julien Palard <julien@eeple.fr>

* Documentation and example of the Python API

2013-08-10 17:45:24 +0200 Julien Palard <julien@eeple.fr>

* Documentation and example of the C API
Expand Down
13 changes: 13 additions & 0 deletions README
Expand Up @@ -59,6 +59,19 @@ C API :

You can find an example of using the C API in examples/example1.c

Python API :
logtop module exposes a logtop class containing :
logtop.__init__(history_size) to build a new logtop keeping
at most history_size lines.
logtop.feed(line) to feed a new line in logtop.
logtop.get(qte_of_elements) to get the top qte_of_elements lines.
logtop.qte_of_elements() to get the current total number of lines.
logtop.timespan() to get the duration from the oldest line to now.

timespan may be less than the runtime, as logtop drop old lines,
to keep, at most, history_size lines, given in the constructor of
the logtop class.

About libavl:
The libavl used here is the Ben Pfaff's one, statically build with logtop, as
Ben want it to be (see INSTALL file and here :
Expand Down
24 changes: 24 additions & 0 deletions examples/example1.py
@@ -0,0 +1,24 @@
#!/usr/bin/env python

import pprint
import sys
sys.path.append('..')

from logtop import logtop


"""
This example show a complete usage of the python API,
It can be used like this :
$ make python-module
$ cat /etc/passwd | cut -d: -f7 | python example1.py
"""

l = logtop(10000)
for line in sys.stdin:
l.feed(line)

pprint.pprint(l.get(10))

0 comments on commit d347e0a

Please sign in to comment.