Skip to main content

Trubrics

A Python client for tracking and analyzing events and LLM interactions with Trubrics.

Overview

Trubrics is a Python client that provides event tracking capabilities with a focus on LLM (Large Language Model) interactions. It is fast and non-blocking, meaning there will be no performance hits to your LLM app. It features an efficient queuing system with automatic background flushing of events to the Trubrics API.

Installation

pip install trubrics

Usage

Setup

Get your project API key from settings in Trubrics. This is a POST only API key.

from trubrics import Trubrics

client = Trubrics(api_key="your-api-key")

Tracking Events

# Track a simple event
client.track(
    user_id="user123",
    event="button_click",
    properties={"button_type": "submit"},
)

# Track LLM interactions
client.track_llm(
    user_id="user123",
    prompt="What is the capital of France?",
    assistant_id="gpt-4",
    generation="The capital of France is Paris.",
    properties={
        "support_tier": "entreprise",
    },
    latency=1.5,  # seconds
    thread_id="user123_thread_id"
)

Closing the Client

# optional closing method to ensure all events are flushed from the queue before exiting your app
client.close()

Logging

The client uses python's logging library to log messages, by default at the ERROR level.

To adjust the verbosity of the default logs, specify the log level:

trubrics = Trubrics(api_key="your-api-key")
trubrics.logger.setLevel(logging.DEBUG)

Or specify your own logger completely:

trubrics = Trubrics(api_key="your-api-key", logger=your_cool_logger)

Other Client Configuration Options

from trubrics import Trubrics

client = Trubrics(
    api_key="your-api-key",
    flush_interval=20,
    flush_batch_size=10,
)
  • flush_interval: Time in seconds between automatic flushes (default: 10)
  • flush_batch_size: Number of events that trigger a flush (default: 20)

Development

Requirements

The project uses the following main dependencies:

  • requests==2.32.3
  • certifi==2025.1.31
  • charset-normalizer==3.4.1
  • idna==3.10
  • urllib3==2.3.0

Setting up Development Environment

Using Make commands:

make setup_uv_venv
make install_dev_requirements  # Install development dependencies
make install_requirements     # Install production dependencies

Publishing

The package is automatically published to PyPI when a new version tag is pushed. To publish a new version:

  • Create a PR from the main branch for the desired changes
  • Update the version in pyproject.toml, and add changelog entry in CHANGELOG.md
  • Once the PR is merged, create a tag in the repo trubrics-python based on the version in pyproject.toml, and push it
    git tag -a v1.0.0 -m "Release version v1.0.0"
    git push origin v1.0.0
    
  • Once the tag is pushed, a Github action release.yml will be triggered. It will:
    • Create a release in the repo trubrics-python based on the CHANGELOG.md entry
    • build the package with uv
    • publish it to PyPI

Metadata

Release files for trubrics 1.8.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 trubrics 1.8.5
File Size Uploaded
trubrics-1.8.5.tar.gz 7.3 kB Details

Built distribution (wheel)

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

Total release size: 14.1 kB

Release files / trubrics-1.8.5.tar.gz

Download URL trubrics-1.8.5.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e275a8a5d56d49b0e779ac7164e06ea52ef1d4eaddbd26f77b0aa2d901083e9b
BLAKE2b-256 checksum
How to use checksums
7c65bce20995e3603958add0d710d43690ce85cfbd5d9d4142f498b86fd6b6bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Release files / trubrics-1.8.5-py3-none-any.whl

Download URL trubrics-1.8.5-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1097bf00c24a93688f9e32ce78b7e72bb042989c5cbc63ad0adadfd01fa2cfe0
BLAKE2b-256 checksum
How to use checksums
2692f738992f8377f0b8df890babfef54a67296b4b16dc7987207d221a88951a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Release history Release notifications | RSS feed

This release

1.8.5 This release

2 release files

1.8.4

2 release files

1.8.3

2 release files

1.8.2

2 release files

1.8.1

2 release files

1.8.0

2 release files

1.7.9

2 release files

1.7.7

2 release files

1.7.4

2 release files

1.7.3

2 release files

1.7.2

2 release files

1.7.1

2 release files

1.7.0

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.9

2 release files

1.2.8

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

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