nathaned / canvasapi

Python API wrapper for Instructure's Canvas LMS

Home Page:https://pypi.python.org/pypi/canvasapi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

canvasapi

canvasapi is a Python package that allows for simple access to the Instructure Canvas API.

Installation

pip install canvasapi

Getting Started

The first thing to do is open a connection with Canvas. You will need to provide the URL for the API endpoint of your Canvas instance as well as a valid API key.

from canvasapi import Canvas

api_url = "https://example.com/api/v1/"  # URL of API for your Canvas instance
api_key = "p@$$w0rd"  # Your API key

canvas = Canvas(api_url, api_key)

You can now use canvas to begin making API calls. Here are some examples:

course = canvas.get_course('1111111')
user = canvas.get_user('5555555')
print user.name

Some calls will return a PaginatedList object instead of a single object.

users = course.get_users()
print users
<PaginatedList of type User>

This PaginatedList object is iterable. However, it doesn't contain any data until called. Calls to the API are made as-needed and results are stored in the object. You can use it like this:

for user in users:
    print user.name

You can also use indices:

print users[2].name

And even slices!

for user in users[2:]:
	print user.name

Warning: Presently, there is no way to determine the exact number of records Canvas might return without brute forcing through all the API calls. This means that PaginatedList is not aware of it's own length and negative indicies and slices (users[-1], users[-1:], etc.) are not possible at this time.

About

Python API wrapper for Instructure's Canvas LMS

https://pypi.python.org/pypi/canvasapi

License:MIT License


Languages

Language:Python 99.9%Language:Shell 0.1%