Skip to main content

Canvas LMS API wrapper

Project description

Canvas API Wrapper

This is a CLI wrapper around the Canvas LMS API

Installation

Installation requires Python 3.10

$ pip install canvas-api-cli
$ canvas --help

Configuration

The config file should be located at $HOME/.config/canvas.toml, and look something like this:

[instance]
default="<nickname>"

[instance.<nickname>]
domain="domain.instructure.com"
token="<API TOKEN>"

To test that it's configured properly you can execute

$ canvas get users/self

And confirm that the output is for your user

Canvas Instances

Each customer or entity that Instructure deals with is given their own Canvas instance with a unique domain name. Each instance is added to your configuration like so:

[instance.<nickname>]
domain="domain.instructure.com"
token="<API TOKEN>"

The Canvas instance to use can then be selected when running a query

$ canvas get users/self -i <nickname>

If no instance is specified then the default will be used. If the configuration does not have a default, then you must specific an instance with every query

[instance]
default="<nickname>"

[instance.<nickname>]
domain="domain.instructure.com"
token="<API TOKEN>"

Usage

You can query Canvas endpoints using the query subcommand and it's aliases (get, post, put and delete)

$ canvas get <endpoint>

The endpoint parameter will simply be the unique part of the API url. For example: The URL: https://canvas.instructure.com/api/v1/accounts/:account_id/users would be queried as

$ canvas get accounts/:account_id/users

Query Parameters

Query Parameters are added using the -q option

$ canvas get :course_id/assignments -q include[]=submission -q all_dates=true

Request Body

The request body for POST or PUT requests is passed in via the -d option

Either as a JSON string:

$ canvas put courses/:course_id/assignments/:assignment_id  -d '
     {
       "assignment": {
         "name": "New Test Name"
       }
     }
     '

Or a filename

$ canvas put courses/:course_id/assignments/:assignment_id  -d @file.json

Piping

When you pipe the output of canvas to another program, syntax highlighting will not be added. This is convenient, because it allows you to pipe to other programs like jq very easily. Additionally, any info that is not the JSON response from Canvas is written to stderr instead of stdout, so you don't have to worry abou those

The JSON output will still be formatted. If you want to disable all of that you can use the --raw flag

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

canvas_api_cli-0.3.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

canvas_api_cli-0.3.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file canvas_api_cli-0.3.0.tar.gz.

File metadata

  • Download URL: canvas_api_cli-0.3.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.9 Linux/6.6.7-arch1-1

File hashes

Hashes for canvas_api_cli-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3f8837be9de84c1eed8ab9bd445ccc7dd28e75c212227ad959ab06c3ae9582b0
MD5 9ac5e773d9ac42bc82d29fcef19f5ec1
BLAKE2b-256 7a756c395831d76840298ce44dd6b42b614590e744ff4deb5cab0d577d06d88c

See more details on using hashes here.

Provenance

File details

Details for the file canvas_api_cli-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: canvas_api_cli-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.9 Linux/6.6.7-arch1-1

File hashes

Hashes for canvas_api_cli-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 440638459f7eefbf3289624e4a1c17530596d049dd878ec427b28f86be2a315e
MD5 3ace1c976bc14ff4179c737271c39986
BLAKE2b-256 7a6257e45688ae3d21b260e13f4f03e47f866bec99592377874dd24b930f8eca

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page