Python Library
Tenzir ships with a Python library to enable interaction with Tenzir with primitives that integrate well with the Python ecosystem. We distribute the library as PyPI package called tenzir.
The Python library is considered experimental and subject to change without notice.
Install the PyPI package
Use pip
to install Tenzir:
Use the Tenzir Python library
Quickstart
The following snippet illustrates a small script to query Tenzir.
Overview
The Python library is meant to expose all the Tenzir features that are relevant in a Python environment. For now though, it is still in active development and only the following interfaces are exposed:
export
count
status
Many options that exist on the CLI are not mapped to the library. The idea here is to avoid overwhelming the API with options that are actually not needed when interacting with Tenzir from Python.
class Tenzir
Create a connection to a Tenzir node that is listening at the specified
endpoint. If no enpdoint is given the TENZIR_ENDPOINT
environment variable is
used, if that is also not present the tenzir.endpoint
value from a local
tenzir.yaml
configuration file is used. In case that value is also not present
the default connection endpoint of 127.0.0.1:5158
is used.
export
Evaluate an expression in a Tenzir node and receive the resulting events in an
asynchronous stream of TableSlices
.
The mode
argument can be set to one of HISTORICAL
, CONTINUOUS
, or
UNIFIED
. A historical export evaluates the expression against data
that is stored in the Tenzir database, the resulting output stream ends
when all eligible data has been evaluated. A CONTINUOUS
one looks at data
as it flows into the node, it will continue to run until the event limit is
reached, it gets discarded, or the node terminates.
The limit
argument sets an upper bound on the number of events that should
be produced. The special value 0
indicates that the number of results is
unbounded.
count
Evaluate the sum of all events in the database that match the given expression.
status
Retrieve the current status from Tenzir.
class TableSlice
Collect a stream of TableSlice
and return a dictionary of Arrow
tables indexed by schema name.
class TenzirRow
A TenzirRow
is a Python native representation of an "event" from Tenzir. It
consists of a name
and a data
dictionary.
Convert a stream of TableSlice
s to a stream of TenzirRow
s.