TrueRecord SDK for Python
TrueRecord keeps a record of every interaction with an AI system in your app. This SDK sends those records. Each message is encrypted before it leaves your process, so only TrueRecord can process it. See the TrueRecord SDK docs for setup and guides.
Requires Python 3.9+.
Install
pip install truerecord-sdk
Quick start
from truerecord_sdk import TrueRecordClient, TrueRecordError
client = TrueRecordClient(
api_key="tr_sk_...",
public_key=open("truerecord_public.pem").read(),
application_guid="...",
interaction_guid="...",
)
try:
# Send the message your user sends to the LLM
client.send(user_message, "user", conversation_ref="session-42")
# Send a message from the LLM to the user
client.send(llm_message, "llm", conversation_ref="session-42")
except TrueRecordError as e:
print(e)
What to send
Each call to send creates a record of one message, either what the user sent ("user") or what the LLM sent ("llm"). Use the same conversation_ref for both so TrueRecord can pair them.
client.send(message, origin, message_datetime=None, conversation_ref=None, hook=None)
| Argument | Required | Description |
|---|---|---|
message |
Yes | The message a user sent to the AI or the AI sent to the user. Can be any value that converts to JSON (string, dict, list, etc.). |
origin |
Yes | "user" if this is a message sent to the LLM, "llm" if it's the LLM's response. Other values are allowed but not supported. |
message_datetime |
No | When the message happened, as an ISO 8601 string (e.g. "2025-01-15T10:30:00Z"). When not set defaults to the current time. |
conversation_ref |
No | A reference you choose (like a session ID or chat ID) to link related messages together. Pass the same value for a user message and its AI response so TrueRecord can pair them. |
hook |
No | A hook name, as a string. |
Implementation details
Non-blocking (recommended)
Sending data to TrueRecord runs in the background so the rest of your code continues without waiting for TrueRecord to respond.
Synchronous apps
For apps using Flask, Django or scripts and CLI tools. Use a thread pool to send in the background.
from concurrent.futures import ThreadPoolExecutor
executor = ThreadPoolExecutor(max_workers=4)
executor.submit(client.send, user_message, "user", conversation_ref="session-42")
executor.submit(client.send, llm_message, "llm", conversation_ref="session-42")
Asynchronous apps
For apps using FastAPI, Starlette, aiohttp or functions defined with async. Use asyncio.create_task to send in the background.
import asyncio
asyncio.create_task(client.asend(user_message, "user", conversation_ref="session-42"))
asyncio.create_task(client.asend(llm_message, "llm", conversation_ref="session-42"))
Blocking
Sending data to TrueRecord waits for TrueRecord to respond before the rest of your code continues.
Synchronous apps
client.send(user_message, "user", conversation_ref="session-42")
client.send(llm_message, "llm", conversation_ref="session-42")
Asynchronous apps
await client.asend(user_message, "user", conversation_ref="session-42")
await client.asend(llm_message, "llm", conversation_ref="session-42")
Errors
All errors extend TrueRecordError, so you can catch them in one place.
| Error | When |
|---|---|
ValidationError |
A required argument is missing or the message can't be serialised to JSON. |
EncryptionError |
The public key isn't a valid RSA key. |
NetworkError |
TrueRecord couldn't be reached after retries. |
AuthenticationError |
The API key was rejected. |
APIError |
Any other server error. Has status_code and detail. |
License
MIT
Metadata
Release files for truerecord-sdk 0.1.4
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 | |
|---|---|---|---|---|
| truerecord_sdk-0.1.4.tar.gz | 9.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| truerecord_sdk-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.8 kB
Release files / truerecord_sdk-0.1.4.tar.gz
| Download URL | truerecord_sdk-0.1.4.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eefce21dffa61a93f9cf989a7c004b7855901ec04720d99c2a477163960f9106
|
|
BLAKE2b-256 checksum How to use checksums |
bdf710b254ba2d661aa522c1caf938cb78d9217c133f908200516d02a44a8c02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / truerecord_sdk-0.1.4-py3-none-any.whl
| Download URL | truerecord_sdk-0.1.4-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
86b54bec26ae7360de4ee842db4e1044cf9d7097de53b9220128109ff1c262dc
|
|
BLAKE2b-256 checksum How to use checksums |
798fc84f04928899609c891554e402425f55acdc10128de85d7ba1a88f58c5a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for truerecord-sdk 0.1.4
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.