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)
| 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, "agent" if it comes from an agent. |
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. |
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.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| truerecord_sdk-0.1.2.tar.gz | 9.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| truerecord_sdk-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.5 kB
Release files / truerecord_sdk-0.1.2.tar.gz
| Download URL | truerecord_sdk-0.1.2.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7da36a82cde4a5d5964dc10daacba35558e51cd22ef6dd467b4399cdd14dc94f
|
|
BLAKE2b-256 checksum How to use checksums |
0b4c5eda800939fe4b65ba327664e9784755d37dd743b5935ca50905c6c3181a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Release files / truerecord_sdk-0.1.2-py3-none-any.whl
| Download URL | truerecord_sdk-0.1.2-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
170668db1d54010a4e8fc44e7a637aed2f3e5e9345feafd46b61ec28df9956dd
|
|
BLAKE2b-256 checksum How to use checksums |
0f9f4aa9736abf487ce8649a242700cc14fd36cacdb14d9318575d58ece2ee11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|