Learnosity SDK for Python

raw JSON →
0.3.13 verified Mon Apr 27 auth: no python

The official Python SDK for integrating with the Learnosity platform. It provides tools for generating secure requests, building question and assessment UIs, and interacting with Learnosity APIs. Current version 0.3.13, released November 2024. The SDK is actively maintained, with regular minor releases.

pip install learnosity-sdk
error ModuleNotFoundError: No module named 'learnosity_sdk'
cause Package not installed in the current environment.
fix
Run pip install learnosity-sdk.
error ImportError: cannot import name 'Init' from 'learnosity_sdk.init'
cause Attempting to import from a deprecated path.
fix
Use from learnosity_sdk import Init instead.
error AttributeError: module 'learnosity_sdk' has no attribute 'Init'
cause The package is too old (pre-0.3.0) or not installed correctly.
fix
Upgrade to latest version: pip install --upgrade learnosity-sdk.
error learnosity_sdk.exceptions.LearnosityException: Invalid signature
cause Consumer secret does not match the key, or request parameters have been tampered with.
fix
Verify your consumer key/secret and ensure you do not modify the generated packet.
deprecated Direct import from `learnosity_sdk.init.Init` is deprecated. Use `from learnosity_sdk import Init`.
fix Change import to `from learnosity_sdk import Init`.
gotcha The `security_packet` parameter in Init constructor was renamed to `security` in recent versions.
fix Use `security` instead of `security_packet`.
breaking Python 3.6 and earlier dropped support. SDK now requires Python 3.7+.
fix Upgrade Python to 3.7 or later.
gotcha Do not modify the generated JSON request packet before sending; changing the structure will break authentication.
fix Use the packet as returned by `init.generate()`.
gotcha The `domain` parameter must match the domain registered in Learnosity, otherwise requests will fail with a security error.
fix Set the `domain` to your application's domain (e.g., 'yourcompany.com').
deprecated `datetime.datetime.utcnow()` used internally in older versions; removed in 0.3.11.
fix Update to SDK >=0.3.11 to avoid deprecation warnings.
pip install learnosity-sdk[quickstart]

Instantiate the Init class with your consumer key/secret and request parameters, then generate the secure request packet.

from learnosity_sdk import Init
init = Init(
    'consumer_key',
    'consumer_secret',
    {
        'domain': 'localhost',
        'user_id': 'demo_student',
        'activity_id': 'demo_activity',
        'session_id': 'demo_session',
        'rendering_type': 'assess',
        'type': 'local_practice',
        'name': 'Demo Activity'
    }
)
request_packet = init.generate()
print(request_packet)