TabPFN Common Utilities
TabPFN Common Utilities (tabpfn-common-utils) provides shared helper functions, primarily focusing on telemetry and logging, used across various TabPFN codebases. It is currently at version 0.2.19 and maintains a frequent release cadence, often with minor updates and bug fixes.
Common errors
-
ModuleNotFoundError: No module named 'posthog'
cause The 'posthog' library, a core dependency for telemetry, is not installed.fixInstall the required dependency: `pip install posthog` or `pip install tabpfn-common-utils` which should pull it in. -
Telemetry events are not appearing in PostHog dashboard.
cause The `TelemetryClient` might not be initialized with a valid `POSTHOG_API_KEY`, or there could be network issues preventing data transmission.fixVerify that the `POSTHOG_API_KEY` environment variable is correctly set and is a valid key for your PostHog instance. Alternatively, ensure you pass a valid `api_key` argument during `TelemetryClient` initialization. Check network connectivity and PostHog server status. -
AttributeError: 'NoneType' object has no attribute 'capture'
cause This usually indicates that the `TelemetryClient` object was not successfully instantiated, or was perhaps inadvertently assigned `None`.fixDouble-check the `TelemetryClient` initialization. Ensure no exceptions occurred during its creation and that it's being used after a successful instantiation. If using `TabPFNLogger`, ensure it's provided with a valid `telemetry_client` instance.
Warnings
- gotcha Telemetry data is sent to PostHog by default. If you need to disable or control this for privacy or compliance, ensure you configure the `TelemetryClient` appropriately or set environment variables like `TABPFN_DISABLE_TELEMETRY`.
- gotcha The `TelemetryClient` relies on the `POSTHOG_API_KEY` environment variable or direct `api_key` argument for proper functioning. If not provided or incorrect, telemetry events may not be sent, or the client might fail silently.
- breaking Older versions (prior to v0.2.14) had an issue with timezone awareness for timestamps. This could lead to incorrect timestamps in telemetry data if not handled carefully.
Install
-
pip install tabpfn-common-utils
Imports
- TelemetryClient
from tabpfn_common_utils.telemetry.client import TelemetryClient
- TabPFNLogger
from tabpfn_common_utils.telemetry.logger import TabPFNLogger
- TelemetryEvent
from tabpfn_common_utils.telemetry.events import TelemetryEvent
Quickstart
import os
from tabpfn_common_utils.telemetry.client import TelemetryClient
from tabpfn_common_utils.telemetry.logger import TabPFNLogger
# Initialize TelemetryClient (API key can be passed directly or via POSTHOG_API_KEY env var)
# For local testing, set POSTHOG_API_KEY in your environment, or pass a dummy string.
# Data won't be sent if API key is invalid or not set in a production context.
telemetry_client = TelemetryClient(
api_key=os.environ.get('POSTHOG_API_KEY', 'phc_dummy_key_for_dev'),
project_group="quickstart",
project_name="example"
)
# Initialize TabPFNLogger
logger = TabPFNLogger(telemetry_client=telemetry_client)
# Log a message
logger.info("Quickstart example executed.")
# Capture a custom event
telemetry_client.capture(
event_name="quickstart_event",
properties={
"data_point_count": 100,
"model_type": "test_model"
}
)
print("Telemetry client and logger initialized and events captured (if API key is valid).")