A python library for building and/or consuming LTI apps
Project description
lti is a Python library implementing the Learning Tools Interperability (LTI) standard. It is based on dce_lti_py, which is based on ims_lti_py.
Installation
pip install lti
Dependencies
Usage
The primary goal of this library is to provide classes for building Python LTI tool providers (LTI apps). To that end, the functionality that you’re looking for is probably in the ToolConfig and ToolProvider classes (ToolConsumer is available too, if you want to consume LTI Providers).
Tool Config Example (Django)
Here’s an example of a Django view you might use as the configuration URL when registering your app with the LTI consumer.
from lti import ToolConfig
from django.http import HttpResponse
def tool_config(request):
# basic stuff
app_title = 'My App'
app_description = 'An example LTI App'
launch_view_name = 'lti_launch'
launch_url = request.build_absolute_uri(reverse('lti_launch'))
# maybe you've got some extensions
extensions = {
'my_extensions_provider': {
# extension settings...
}
}
lti_tool_config = ToolConfig(
title=app_title,
launch_url=launch_url,
secure_launch_url=launch_url,
extensions=extensions,
description = app_description
)
# or you may need some additional LTI parameters
lti_tool_config.cartridge_bundle = 'BLTI001_Bundle'
lti_tool_config.cartridge_icon = 'BLTI001_Icon'
lti_tool_config.icon = 'http://www.example.com/icon.png'
return HttpResponse(lti_tool_config.to_xml(), content_type='text/xml')
Tool Provider OAuth Request Validation Example (Django)
from lti.contrib.django import DjangoToolProvider
from my_app import RequestValidator
# create the tool provider instance
tool_provider = DjangoToolProvider.from_django_request(request=request)
# the tool provider uses the 'oauthlib' library which requires an instance
# of a validator class when doing the oauth request signature checking.
# see https://oauthlib.readthedocs.org/en/latest/oauth1/validator.html for
# info on how to create one
validator = RequestValidator()
# validate the oauth request signature
ok = tool_provider.is_valid_request(validator)
# do stuff if ok / not ok
Tool Consumer Example (Django)
In your view:
def index(request):
consumer = ToolConsumer(
consumer_key='my_key_given_from_provider',
consumer_secret='super_secret',
launch_url='provider_url',
params={
'lti_message_type': 'basic-lti-launch-request'
}
)
return render(
request,
'lti_consumer/index.html',
{
'launch_data': consumer.generate_launch_data(),
'launch_url': consumer.launch_url
}
)
At the template:
<form action="{{ launch_url }}"
name="ltiLaunchForm"
id="ltiLaunchForm"
method="POST"
encType="application/x-www-form-urlencoded">
{% for key, value in launch_data.items %}
<input type="hidden" name="{{ key }}" value="{{ value }}"/>
{% endfor %}
<button type="submit">Launch the tool</button>
</form>
Testing
Unit tests can be run by executing
tox
This uses tox to set up and run the test environment.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file lti-0.9.5.tar.gz
.
File metadata
- Download URL: lti-0.9.5.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1ddd59d1beacf06ba67d8c96417581043398eb2283eb66141c660f6ecae1814 |
|
MD5 | 27f7555372167514fef58e4e073800bb |
|
BLAKE2b-256 | 6fe4f239f3c653d8443b1bcfb0f359d8046f17e0226001cb52ea8e8e95071b07 |
File details
Details for the file lti-0.9.5-py2.py3-none-any.whl
.
File metadata
- Download URL: lti-0.9.5-py2.py3-none-any.whl
- Upload date:
- Size: 21.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aafdfcd35e094d6606cce19c4fe7c34cf7dcc801fdfa61c5e874ef57c00160d5 |
|
MD5 | 11a1383e2f214a9da8c4705d35623e75 |
|
BLAKE2b-256 | 4cfb3545582f7e2e81134d289e51d91342e016e27a3b56f1a7ed6460e65dfb31 |