Official Python SDK for xR2 — prompt management platform for AI applications
Project description
xR2 SDK (Python)
Official Python SDK for xR2 — a platform for managing, testing, and analyzing AI prompts in production. Use it to ship prompt changes safely with experiments, track performance and user journeys, and integrate via API/SDKs.
Website: https://xr2.uk/
What is xR2?
xR2 helps you manage, version, and optimize prompts for your AI-powered applications:
- Prompt Management — Store and organize all your prompts in one place
- Version Control — Track changes, test different versions, and roll back when needed
- A/B Testing — Run experiments to find the best performing prompts
- Analytics — Track events and measure the impact of your prompts on user behavior
Installation
pip install xr2-sdk
Quickstart (Sync)
from xr2_sdk.client import xR2Client
client = xR2Client(api_key="YOUR_PRODUCT_API_KEY")
# Check API key validity
key_response = client.check_api_key()
if key_response.ok:
print(f"API key valid for user: {key_response.data.user}")
# Get prompt
prompt_response = client.get_prompt(slug="welcome")
if prompt_response.ok:
prompt = prompt_response.data
print(f"slug: {prompt.slug}")
print(f"version_number: {prompt.version_number}")
print(f"system_prompt: {prompt.system_prompt}")
print(f"user_prompt: {prompt.user_prompt}")
print(f"variables: {prompt.variables}")
print(f"trace_id: {prompt.trace_id}")
# Track an event
event_response = client.track_event(
trace_id=prompt.trace_id,
event_name="sign_up",
user_id="user_123",
metadata={},
)
if event_response.ok:
print(f"Event tracked: {event_response.data.event_id}")
# Track a purchase event with value
purchase_response = client.track_event(
trace_id=prompt.trace_id,
event_name="purchase_completed",
user_id="user_123",
value=99.99,
currency="USD",
metadata={"order_id": "order_67890", "product_id": "prod_456"},
)
Quickstart (Async)
import asyncio
from xr2_sdk.client import AsyncxR2Client
async def main():
client = AsyncxR2Client(api_key="YOUR_PRODUCT_API_KEY")
try:
# Check API key validity
key_response = await client.check_api_key()
if key_response.ok:
print(f"API key valid for user: {key_response.data.user}")
# Get prompt
prompt_response = await client.get_prompt(slug="welcome")
if prompt_response.ok:
prompt = prompt_response.data
print(f"slug: {prompt.slug}")
print(f"version_number: {prompt.version_number}")
print(f"system_prompt: {prompt.system_prompt}")
print(f"user_prompt: {prompt.user_prompt}")
print(f"variables: {prompt.variables}")
print(f"trace_id: {prompt.trace_id}")
# Track an event
event_response = await client.track_event(
trace_id=prompt.trace_id,
event_name="sign_up",
user_id="user_123",
metadata={},
)
if event_response.ok:
print(f"Event tracked: {event_response.data.event_id}")
# Track a purchase event with value
purchase_response = await client.track_event(
trace_id=prompt.trace_id,
event_name="purchase_completed",
user_id="user_123",
value=99.99,
currency="USD",
metadata={"order_id": "order_67890", "product_id": "prod_456"},
)
finally:
await client.aclose()
asyncio.run(main())
Endpoints
- GET
/api/v1/check-api-key→ validates API key and returns username - POST
/api/v1/get-prompt→ returns prompt content andtrace_id - POST
/api/v1/events→ records an event associated withtrace_id
Configuration
api_key: Product API key (sent asAuthorization: Bearer <key>)timeout: Request timeout (seconds)total_retries,backoff_factor: Retry policy (sync) / lightweight retry (async)
API Methods
check_api_key()
Validate your API key and get the associated username.
Parameters: None
Returns: Response[CheckAPIKeyResponse]
response.data.ok: AlwaysTrueif validresponse.data.user: Username of the API key owner
get_prompt()
Parameters:
slug(required): The prompt slug identifierversion_number(optional): Specific version number to fetchstatus(optional): Version status filter -draft,testing,production,inactive,deprecated
Returns: Response[PromptContentResponse]
- Access data:
response.data.trace_id,response.data.user_prompt, etc. - Check success:
if response.ok:
track_event()
Required Parameters:
trace_id: Trace ID fromget_prompt()responseevent_name: Event name as defined in dashboard (e.g., "sign_up", "purchase_completed")
Optional Parameters:
user_id: User identifier for trackingsession_id: Session identifier for analyticsvalue: Numeric value (for revenue tracking, order amounts, etc.)currency: Currency code (e.g., "USD", "EUR")metadata: Dictionary of custom fields as defined in event definition schema
Returns: Response[EventResponse]
- Access data:
response.data.event_id,response.data.timestamp, etc. - Check success:
if response.ok:
Important Notes:
- Before tracking events, define them at https://xr2.uk/analytics/events
- Set event name and required/optional fields in the dashboard
- Field validation happens automatically based on your event definitions
- Events are deduplicated by
trace_id+event_name
Links
- Website: https://xr2.uk/
- Documentation: https://xr2.uk/docs
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xr2_sdk-0.2.6.tar.gz.
File metadata
- Download URL: xr2_sdk-0.2.6.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b271fd0a2d60a9bf406b2f66e15533830ee14206298fcf48a3290ca12dd1735c
|
|
| MD5 |
c5007e5c1a60076bc9f468eb1cf6b2f5
|
|
| BLAKE2b-256 |
754414af828646cbe187e6ea391badf534a2d1e36a171b8bd64a005ebf69202a
|
File details
Details for the file xr2_sdk-0.2.6-py3-none-any.whl.
File metadata
- Download URL: xr2_sdk-0.2.6-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6aa4b8fde4e5e453a3d66554e99cc99d7c1320064dd1448009db95b9a9b7b7b
|
|
| MD5 |
1509eecf2739d8c970cac13d1a08b33c
|
|
| BLAKE2b-256 |
fcff1818ff483c52b395b52da1c25e8d88350028fedecabcfd7a6f5687c1221b
|