tetragon-client
A typed Python client for Cilium Tetragon, the eBPF security observability and runtime enforcement tool. It works with Tetragon on Kubernetes or, as here, on a plain Docker host.
- The whole gRPC API. Stream events live; load, list, configure and delete tracing policies; check health; change log levels; dump the process cache; tune export rotation. Sync and asyncio clients.
- Export files without gaps.
ExportFileReaderreads Tetragon's JSON export (--export-filename), follows its rotation (including gzipped backups) and resumes from a checkpoint after a restart or crash, so your program misses nothing while it's down. - One event type. Both sources give you the same
GetEventsResponseprotobuf messages (or plain dicts), so your handling code doesn't care where events came from. - Typed and packaged. Ships type stubs (
py.typed), is checked withmypy --strict, and is available from PyPI and as Debian, Ubuntu and Fedora packages.
It's a general-purpose library: anything that wants Tetragon events (a SIEM forwarder, an alerting script, a compliance tool's ingester) can use it.
Install
From PyPI with pip or pipx:
pip install tetragon-client
On Debian 12/13 and Ubuntu 24.04 / 26.04, from the mig5 apt repository:
sudo mkdir -p /usr/share/keyrings
curl -fsSL https://mig5.net/static/mig5.asc | sudo gpg --dearmor -o /usr/share/keyrings/mig5.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/mig5.gpg] https://apt.mig5.net $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mig5.list
sudo apt update
sudo apt install python3-tetragon-client
On Fedora 43 / 44, from the mig5 rpm repository:
sudo rpm --import https://mig5.net/static/mig5.asc
sudo tee /etc/yum.repos.d/mig5.repo > /dev/null << 'EOF'
[mig5]
name=mig5 Repository
baseurl=https://rpm.mig5.net/$releasever/rpm/$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mig5.net/static/mig5.asc
EOF
sudo dnf install python3-tetragon-client
The release key's fingerprint is 54A9 1143 AE0A B4F7 743B 01FE 888E D1B4 23A3 BC99.
PyPI releases come with detached signatures and a signed SHA256SUMS.
Quick start
Live events over gRPC
from tetragon_client import TetragonClient, event_filter, event_kind
with TetragonClient() as client: # unix:///var/run/tetragon/tetragon.sock
print("Tetragon", client.version())
for event in client.events(allow=[event_filter(kinds=["process_exec"])]):
proc = event.process_exec.process
print(proc.binary, proc.arguments)
The stream reconnects by itself when Tetragon restarts. Events emitted while it's disconnected are not replayed; read the export file when every event matters.
Every event, from the export file
from tetragon_client import ExportFileReader, FileCheckpoint
reader = ExportFileReader(
"/var/log/tetragon/tetragon.log",
FileCheckpoint("/var/lib/my-ingester/tetragon.pos"),
)
with reader:
for event in reader: # follows rotation; resumes where it stopped
handle(event)
Delivery is at-least-once: after a crash, the last few events may be delivered again. (Under extreme load Tetragon can drop events before they reach the file at all; see export files.)
To store each event exactly once, keep the position in your own database and commit it with the events (examples/sqlite_checkpoint.py).
Managing policies
with TetragonClient() as client:
for policy in client.list_tracing_policies():
print(policy.name, policy.state, policy.mode)
client.configure_tracing_policy("file-monitoring-filtered", mode="monitor")
From the shell
tetragon-events grpc --kind process_exec
tetragon-events file /var/log/tetragon/tetragon.log --checkpoint ~/.tetragon.pos
tetragon-events version
Each event is printed as one line of JSON, in the same shape as
tetra getevents -o json.
Running Tetragon for this library
With Tetragon in Docker, the client needs the gRPC socket and, for
ExportFileReader, the export directory mounted on the host:
docker run --name tetragon --rm --pull always \
--pid=host --cgroupns=host --privileged \
-v /sys/kernel/btf/vmlinux:/var/lib/tetragon/btf \
-v /etc/tetragon/tetragon.tp.d:/etc/tetragon/tetragon.tp.d:ro \
-v /var/run/tetragon:/var/run/tetragon \
-v /var/log/tetragon:/var/log/tetragon \
quay.io/cilium/tetragon:v1.8.0 \
--export-filename /var/log/tetragon/tetragon.log \
--export-file-max-size-mb 100 --export-file-max-backups 20 --export-file-compress
See docs/deployment.md for permissions, retention and security.
Documentation
- Deployment: Tetragon flags, socket and file access, retention, security.
- gRPC client: events and filters, reconnection, every API method, asyncio, TLS.
- Export files: rotation, checkpoints, delivery guarantees, custom stores.
- Writing an ingester: choosing a source, error handling, deduplication.
- Command line:
tetragon-events. - Protobuf compatibility: supported versions, distro packages, updating Tetragon's API.
- Examples: streaming, enforcement alerts, checkpointed ingestion, exactly-once storage, policy management.
- Contributing and releasing.
Compatibility
| Python | 3.11 to 3.14 |
| Tetragon API | generated from v1.8.0 (TETRAGON_VERSION); newer servers work, and unknown fields and event kinds are tolerated |
| PyPI wheel | grpcio ≥ 1.71.2, protobuf ≥ 5.29 and < 8 |
| Debian / Ubuntu / Fedora packages | the distribution's own python3-grpcio and python3-protobuf |
Licence
Apache-2.0. The vendored Tetragon API definitions in proto/ and the code
generated from them are Apache-2.0, © Authors of Hubble/Tetragon.
Metadata
Release files for tetragon-client 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tetragon_client-0.1.0.tar.gz | 134.3 kB | Without provenance | Details for tetragon_client-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tetragon_client-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tetragon_client-0.1.0-py3-none-any.whl |
Total release size: 223.0 kB
Release files / tetragon_client-0.1.0.tar.gz
| Download URL | tetragon_client-0.1.0.tar.gz |
|---|---|
| Size | 134.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
974e88489bff5d736453ff1c606fa6cf17d58e1ce51fb451a90ae212ff51164a
|
|
BLAKE2b-256 checksum How to use checksums |
fb76f812a6da492df9bc1f25efe7b9f7c874725ef9b491e8d6ea523c8b706bb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.13.5 Linux/6.18.62-1.qubes.fc41.x86_64
|
Release files / tetragon_client-0.1.0-py3-none-any.whl
| Download URL | tetragon_client-0.1.0-py3-none-any.whl |
|---|---|
| Size | 88.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ff47509f1e9e45a946f97d54c1ca55400c05109581696636b82ceff1f72adfba
|
|
BLAKE2b-256 checksum How to use checksums |
5d3f8ec571b245fb74dc4a265011e36f8d015a46c716104b63062ca14157be4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.13.5 Linux/6.18.62-1.qubes.fc41.x86_64
|
Security for tetragon-client 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.