📜  canvas api python pypi - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:40:01.173000             🧑  作者: Mango

Canvas API Python PyPI - Shell/Bash

Canvas API Python PyPI is a Python package that provides developers with a programmatic interface to the Canvas Learning Management System's REST API. With this package, developers can create, update, and delete courses, users, and other Canvas objects, as well as retrieve information about them.

Installation

This package is available on PyPI and can be installed using pip. To install from PyPI, run the following command:

pip install canvasapi
Usage

After installation, you can import the Canvas API Python PyPI package by adding the following line to your Python code:

from canvasapi import Canvas
Authentication

To authenticate with the Canvas API, you will need your Canvas API token. You can generate this token from your Canvas account settings.

Once you have your API token, you can authenticate with the following code:

canvas = Canvas("https://yourcanvasurl.instructure.com", "yourapitoken")
Working with Courses

To obtain a list of all courses on your Canvas, use the following code:

courses = canvas.get_courses()
for course in courses:
    print(course.name)

You can create a new course using the following code:

new_course = canvas.create_course(course={"name": "New Course", "course_code": "NC101", "public_syllabus": True})

To update a course, use the course ID and call the edit method:

updated_course = canvas.get_course(course_id)
updated_course.edit(course={"name": "Updated Course Name"})
Working with Users

To obtain a list of all users on your Canvas, use the following code:

users = canvas.get_users()
for user in users:
    print(user.name)

You can create a new user using the following code:

new_user = canvas.create_user(user={"name": "New User", "sortable_name": "User, New", "email": "newuser@example.com"})

To update a user, use the user ID and call the edit method:

updated_user = canvas.get_user(user_id)
updated_user.edit(user={"name": "Updated User Name", "sortable_name": "User, Updated"})
Conclusion

Canvas API Python PyPI is a powerful tool for developers looking to interact programmatically with the Canvas LMS. With simple yet powerful methods, you can easily create, update, and delete courses, users, and other Canvas objects. So give it a try today and start building your own Canvas integrations!