Skip to main content

Learnosity CLI tool (lrn-cli)

PyPI version GitHub version

lrn-cli logo

The lrn-cli tool allows the exchange of JSON payloads with the Learnosity APIs without having to worry about signature generation.

PLEASE NOTE: This is experimental software, and is provided as-is. It is not part of the Learnosity product offering that receives support.

In a nutshell, it can be used as follows:

lrn-cli [--profile <PROFILE>|--consumer-key <KEY> --consumer-secret <SECRET>] [--region <REGION>]
	  --request-json '<REQUEST>' [--update|--set|--delete] \
	  <API> <ENDPOINT>

By default, the demonstration consumer credentials will be used if none are specified.

If --request-json is not specified, the request will be read from standard input, or an alternative JSON file can be provided through --file.

Documentation about all the options is available with the --help flag to both the base tool, and each API.

lrn-cli --help

Getting started

Setup

The simplest way to install, if you don't intend to develop, is via pip3 (or pip).

pip3 install lrn-cli

If you intend to make changes to the codebase, you can get run from a clone of the git repository.

git clone git@github.com:Learnosity/lrn-cli
cd lrn-cli
make
. .venv/lrn-cli/bin/activate

See at the end of this file for other development-related information.

Trogon UI

If you want to try out the Trogon UI, you will need to install the specific dependencies with

pip3 install lrn-cli[trogon]

You can then run it with

lrn-cli tui

Docker

You can build a Docker image with

make docker

You can then use the lrn-cli-docker.sh script to run from this image, with the correct environment and mounts set up as needed.

There may not be complete feature parity for file-based interactions (particularly with relative paths). Access to the current directory should work.

Configuration

While most parameters (credentials, environment, version, region, ...) can be specified on the command line, they can also be set as environment variables (LRN_... as documented in the --help output of the main and sub-commands, if relevant).

lrn-cli also supports credentials and configuration files. By default, these are ~/.learnosity/credentials and ~/.learnosity/config respectively. You may need to create a ~/.learnosity directory before creating these files.

Both are formatted as simple INI file, with sections in square brackets, and parameters set within the section. Those entries can be selected for use with either the --profile command line option, or the LRN_PROFILE environment variable.

If the profile provided is not found, and keys not otherwise specified, lrn-cli will default to the learnosity-demos consumer key.

Credentials file

The credentials file allows you to specify named consumer key and secret pairs. By default, it is in ~/.learnosity/credentials.

[default]
consumer_key=yis0TYCu7U9V4o7M
consumer_secret=74c5fd430cf1242a527f6223aebd42d30464be22

[some-other-consumer]
consumer_key=X
consumer_secret=Y

[staging]
consumer_key=X
consumer_secret=Y

Configuration file

The config file allows additional parameters to be specified, such as environment, region and version. By default, it is in ~/.learnosity/config.

[default]
region=au
version=v2020.2.LTS

[old-lts]
version=v2020.1.LTS
source_profile=default

[staging]
environment=staging
version=v2020.2.LTS

The source_profile allows to fetch a differently-named set of consumers credentials.

Action

The default action is GET. Different actions can be selected by using the switches --set, --update, or --delete. These are mutually exclusive: if more than one occurs, the last will be the effective action. (There is a --get switch as well, though this is less useful, since GET is the default.)

Examples

Getting the status of a session, passing the request from the command line arguments.

$ API=data
$ ENDPOINT=/sessions/statuses
$ lrn-cli -l debug -R  '{ "limit": 1, "session_ids": ["4562ae00-0f59-6d3c-860b-74b7b5579b32"] }' ${API} ${ENDPOINT}
2019-10-22 14:22:25,490 DEBUG:Using request JSON from command line argument
2019-10-22 14:22:25,491 DEBUG:Sending GET request to https://data.learnosity.com/v1/sessions/statuses ...
[
 {
  "user_id": "open_web_demo1",
  "activity_id": "Demo Activity Id",
  "num_attempted": 0,
  "num_questions": 5,
  "session_id": "4562ae00-0f59-6d3c-860b-74b7b5579b32",
  "session_duration": 0,
  "status": "Incomplete",
  "dt_saved": "2019-10-21T23:48:31Z",
  "dt_started": "2019-10-21T23:48:29Z",
  "dt_completed": null
 }
]

Getting the last authored Item, passing the request from standard input.

$ echo '{ "limit": 1 }' | lrn-cli -l debug data /itembank/items
2019-10-22 14:24:07,108 DEBUG:Reading request json from <_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>...
2019-10-22 14:24:07,108 DEBUG:Sending GET request to https://data.learnosity.com/v1/itembank/items ...
[
 {
  "reference": "1de592c9-0af5-4a58-8d47-75c304ec654e",
  "title": null,
  "workflow": null,
  "metadata": null,
  "note": "",
  "source": "",
  "definition": {
   "widgets": [
    {
     "reference": "10f24a41-64ad-4d08-ab44-cc7469e324ba",
     "widget_type": "response"
    },
    {
     "reference": "27093a4b-19cb-4517-9d47-557241577ec2",
     "widget_type": "response"
    }
   ],
   "template": "dynamic"
  },
  "description": "",
  "status": "published",
  "questions": [
   {
    "reference": "10f24a41-64ad-4d08-ab44-cc7469e324ba",
    "type": "mcq"
   },
   {
    "reference": "27093a4b-19cb-4517-9d47-557241577ec2",
    "type": "mcq"
   }
  ],
  "features": [],
  "tags": {}
 }
]

Development

A few handy dependencies to support development can be installed in the virtualenv with

make venv-dev

Running Tests

Run make test.

Creating a new release

Run make release.

This requires GNU-flavoured UNIX tools (particularly gsed). If these are not the default on your system, you'll need to install them, e.g. for OS X,

brew install gsed coreutils

Deploying to PyPi

Releases are automatically pushed to PyPi when created in GitHub, using the Trusted Publishers system.

Manualy releases can be triggered with make dist-upload, provided you have the necessary PyPi permissions.

Metadata

Release files for lrn-cli 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lrn-cli 1.0.0
File Size Uploaded Provenance
lrn_cli-1.0.0.tar.gz 43.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for lrn-cli 1.0.0
File Interpreter ABI Platform
lrn_cli-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 59.6 kB

Release files / lrn_cli-1.0.0.tar.gz

Download URL lrn_cli-1.0.0.tar.gz
Size 43.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b5604744400219c82ee5ee33a056aabaa2759f66521645178a706bb8e0c4f0c7
BLAKE2b-256 checksum
How to use checksums
0a955ad675bc2a7af45eac62477e757189fb97f4ca1fb7831a35059e6e81a5f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / lrn_cli-1.0.0-py3-none-any.whl

Download URL lrn_cli-1.0.0-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94e65f477e02c17fd14e8079b9eeba8ee4fe692897d4285905ca82aa463e13a2
BLAKE2b-256 checksum
How to use checksums
f27bf427bbdc7ae924ff545d052941a20576f0d8541995486b2082945414ef23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Security for lrn-cli 1.0.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page