This release is a pre-release and may not be stable for production use.
timeback-caliper
Python client for sending Caliper learning analytics events to Timeback.
Installation
# pip
pip install timeback-caliper
# uv (add to a project)
uv add timeback-caliper
# uv (install into current environment)
uv pip install timeback-caliper
Quick Start
from timeback_caliper import (
CaliperClient,
ActivityCompletedInput,
TimebackUser,
TimebackActivityContext,
TimebackApp,
TimebackActivityMetric,
)
# Initialize client
client = CaliperClient(
env="staging", # or "production"
client_id="your-client-id",
client_secret="your-client-secret",
)
# Send an activity completed event
result = await client.events.send_activity(
sensor_id="https://myapp.example.com/sensors/main",
input=ActivityCompletedInput(
actor=TimebackUser(
id="https://example.edu/users/123",
email="student@example.edu",
),
object=TimebackActivityContext(
id="https://myapp.example.com/activities/456",
subject="Math",
app=TimebackApp(name="My Learning App"),
),
metrics=[
TimebackActivityMetric(type="totalQuestions", value=10),
TimebackActivityMetric(type="correctQuestions", value=8),
TimebackActivityMetric(type="xpEarned", value=150),
],
),
)
# Wait for processing
status = await client.jobs.wait_for_completion(result.job_id)
print(f"Processed {status.events_processed} events")
FastAPI Integration
from fastapi import FastAPI, HTTPException
from timeback_caliper import (
CaliperClient,
ActivityCompletedInput,
APIError,
)
app = FastAPI()
# Initialize client (reuse across requests)
caliper = CaliperClient(
env="staging",
client_id="...",
client_secret="...",
)
@app.post("/api/activity")
async def submit_activity(input: ActivityCompletedInput):
"""Submit a learning activity event."""
try:
result = await caliper.events.send_activity(
sensor_id="https://myapp.example.com/sensors/main",
input=input,
)
return {"success": True, "job_id": result.job_id}
except APIError as e:
raise HTTPException(status_code=e.status_code or 500, detail=str(e))
@app.on_event("shutdown")
async def shutdown():
await caliper.close()
Event Types
ActivityCompletedEvent
Records when a student completes an activity with performance metrics:
from timeback_caliper import (
ActivityCompletedInput,
TimebackUser,
TimebackActivityContext,
TimebackApp,
TimebackCourse,
TimebackActivityMetric,
)
input = ActivityCompletedInput(
actor=TimebackUser(
id="https://example.edu/users/123",
email="student@example.edu",
name="Jane Doe",
role="student",
),
object=TimebackActivityContext(
id="https://myapp.example.com/activities/456",
subject="Math",
app=TimebackApp(name="My Learning App"),
course=TimebackCourse(name="Algebra 101"),
),
metrics=[
TimebackActivityMetric(type="totalQuestions", value=10),
TimebackActivityMetric(type="correctQuestions", value=8),
TimebackActivityMetric(type="xpEarned", value=150),
TimebackActivityMetric(type="masteredUnits", value=1),
],
)
result = await client.events.send_activity(sensor_id, input)
TimeSpentEvent
Records time spent on an activity:
from timeback_caliper import TimeSpentInput, TimeSpentMetric
input = TimeSpentInput(
actor=TimebackUser(id="...", email="..."),
object=TimebackActivityContext(id="...", subject="Reading", app=TimebackApp(name="...")),
metrics=[
TimeSpentMetric(type="active", value=1800), # 30 minutes
TimeSpentMetric(type="inactive", value=300), # 5 minutes
],
)
result = await client.events.send_time_spent(sensor_id, input)
Job Tracking
Events are processed asynchronously. Track processing status:
# Get job status
status = await client.jobs.get_status(job_id)
print(f"Status: {status.status}")
# Wait for completion (with timeout)
status = await client.jobs.wait_for_completion(
job_id,
timeout=60.0, # Max wait time
poll_interval=1.0, # Check every second
)
if status.status == "completed":
print(f"Processed {status.events_processed} events")
elif status.status == "failed":
print(f"Failed: {status.error}")
Context Manager
Use the client as an async context manager for automatic cleanup:
async with CaliperClient(client_id="...", client_secret="...") as client:
await client.events.send_activity(sensor_id, input)
# Client is automatically closed
Error Handling
from timeback_caliper import (
CaliperClient,
AuthenticationError,
APIError,
)
try:
result = await client.events.send_activity(sensor_id, input)
except AuthenticationError:
print("Invalid credentials")
except APIError as e:
print(f"API error ({e.status_code}): {e}")
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
env |
str |
None |
"staging" or "production" |
base_url |
str |
auto | Override API URL |
auth_url |
str |
auto | Override auth URL |
client_id |
str |
env var | OAuth2 client ID |
client_secret |
str |
env var | OAuth2 client secret |
timeout |
float |
30.0 |
Request timeout in seconds |
Environment Variables
CALIPER_CLIENT_ID=your-client-id
CALIPER_CLIENT_SECRET=your-client-secret
CALIPER_BASE_URL=https://api.staging.timeback.com
CALIPER_TOKEN_URL=https://auth.staging.timeback.com/oauth2/token
Metadata
Release files for timeback-caliper 0.2.2b20260326152502
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 | Actions |
|---|---|---|---|---|
| timeback_caliper-0.2.2b20260326152502.tar.gz | 35.8 kB | Without provenance | Details for timeback_caliper-0.2.2b20260326152502.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| timeback_caliper-0.2.2b20260326152502-py3-none-any.whl | Python 3 | none | any | Details for timeback_caliper-0.2.2b20260326152502-py3-none-any.whl |
Total release size: 68.2 kB
Release files / timeback_caliper-0.2.2b20260326152502.tar.gz
| Download URL | timeback_caliper-0.2.2b20260326152502.tar.gz |
|---|---|
| Size | 35.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0179c1e72e5bf8e9f9ddd6a307c83e5782723c83bbd100dfa4f1cb6b0f6a6913
|
|
BLAKE2b-256 checksum How to use checksums |
641e49867ae53409b9e4f0d987cca409e17a3c35f84f620dd703675772d79fa2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / timeback_caliper-0.2.2b20260326152502-py3-none-any.whl
| Download URL | timeback_caliper-0.2.2b20260326152502-py3-none-any.whl |
|---|---|
| Size | 32.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b7d4383b95eff7cde0d17379da663538f809188973436c324ce3e993ecdfb0d
|
|
BLAKE2b-256 checksum How to use checksums |
ad29094842cc7e1bf6f58bc8685fe2852b80974f99fb01e30a1f4a78098da013
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for timeback-caliper 0.2.2b20260326152502
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.