TinCan Python

raw JSON →
1.0.0 verified Fri May 01 auth: no python

A Python library for implementing the Tin Can API (Experience API / xAPI), used for tracking learning experiences. Current version 1.0.0. Release cadence is low; no active development observed since initial release.

pip install tincan
error NameError: name 'RemoteLRS' is not defined
cause Importing incorrectly, e.g., 'import tincan' then using tincan.RemoteLRS without dot access or missing import.
fix
Use 'from tincan import RemoteLRS' or 'import tincan' then 'tincan.RemoteLRS'.
error TypeError: 'module' object is not callable
cause Trying to instantiate the module itself, e.g., 'tincan(...)' instead of 'tincan.RemoteLRS(...)'.
fix
Ensure you call the class, not the module: 'RemoteLRS(...)' or 'tincan.RemoteLRS(...)'.
error requests.exceptions.ConnectionError: ...
cause Invalid endpoint URL or network issue when saving a statement.
fix
Verify the LRS endpoint URL and network connectivity. Check if authentication is required.
gotcha The library uses a custom JSON serialization for statements. When constructing verbs and activities, ensure you follow the exact object structure (e.g., verb must have 'id' and 'display' keys).
fix Use dictionaries with required keys as shown in the quickstart.
gotcha RemoteLRS does not verify the connection or credentials until you actually send a statement. You'll get an error only at save_statement time.
fix Wrap calls in try/except and check for exceptions.
gotcha The library may not support all xAPI extensions out of the box; custom extensions require manual construction.
fix Refer to xAPI spec and build extensions as nested dicts.

Basic usage: configure LRS, create a statement, and save it.

from tincan import RemoteLRS, Statement, Agent, Activity

# Configure Remote LRS connection
lrs = RemoteLRS(
    endpoint='https://example.com/lrs',
    username='',
    password=''
)

# Create a statement
agent = Agent(name='John Doe', mbox='mailto:john@example.com')
activity = Activity(id='http://example.com/activity', definition={'name': {'en-US': 'Test Activity'}})
statement = Statement(actor=agent, verb={"id": "http://adlnet.gov/expapi/verbs/experienced", "display": {"en-US": "experienced"}}, object=activity)

# Send statement
response = lrs.save_statement(statement)
print(response)