API wrapper for the Canvas LMS
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
User profile operations, enrollment handling, file management, communication channels, and user-specific Canvas functionality. The User class provides comprehensive access to user data and capabilities.
Manage user profiles, personal information, and account settings.
class User(CanvasObject):
def get_profile(self, **kwargs) -> dict:
"""
Get user profile information.
Returns:
Dictionary with profile data including name, email, bio, avatar_url, etc.
"""
def edit(self, **kwargs) -> User:
"""
Edit user profile.
Parameters:
- name: User's full name
- short_name: User's display name
- sortable_name: Name for sorting (Last, First)
- email: Primary email address
- bio: User biography
- pronouns: User pronouns
Returns:
Updated User object
"""
def get_avatars(self, **kwargs) -> PaginatedList[Avatar]:
"""Get available avatars for the user."""Access user's courses, enrollments, and academic information.
def get_courses(self, **kwargs) -> PaginatedList[Course]:
"""
List courses for the user.
Parameters:
- enrollment_type: Filter by enrollment type ('student', 'teacher', 'ta', etc.)
- enrollment_role: Filter by specific role
- enrollment_state: Filter by enrollment state ('active', 'invited', 'completed')
- include: Additional data ('needs_grading_count', 'syllabus_body', etc.)
- state: Filter by course workflow state ('available', 'completed', 'deleted')
Returns:
Paginated list of Course objects
"""
def get_enrollments(self, **kwargs) -> PaginatedList[Enrollment]:
"""
List enrollments for the user.
Parameters:
- type: Filter by enrollment type
- role: Filter by enrollment role
- state: Filter by enrollment state
- include: Additional data ('avatar_url', 'group_ids', 'locked', etc.)
Returns:
Paginated list of Enrollment objects
"""
def get_missing_submissions(self, **kwargs) -> PaginatedList[Assignment]:
"""
Get assignments with missing submissions for the user.
Parameters:
- include: Additional data ('course', 'planner_override')
- filter: Date range filter
Returns:
Paginated list of Assignment objects with missing submissions
"""Access user's assignments, submissions, and academic progress.
def get_assignments(self, **kwargs) -> PaginatedList[Assignment]:
"""
List assignments for the user across all courses.
Parameters:
- course_ids: List of course IDs to filter by
- include: Additional data ('submission', 'assignment_visibility', etc.)
Returns:
Paginated list of Assignment objects
"""
def get_user_assignments(self, course, **kwargs) -> PaginatedList[Assignment]:
"""
Get assignments for the user in a specific course.
Parameters:
- course: Course object or course ID
- include: Additional data to include
Returns:
Paginated list of Assignment objects
"""Manage user's personal files and folder organization.
def get_files(self, **kwargs) -> PaginatedList[File]:
"""
List files for the user.
Parameters:
- content_types: Filter by content type
- exclude_content_types: Exclude specific content types
- search_term: Search term to filter files
- include: Additional data ('user', 'usage_rights')
- only: Filter by file type ('names', 'folders')
- sort: Sort files by field ('name', 'size', 'created_at', 'updated_at')
- order: Sort order ('asc', 'desc')
Returns:
Paginated list of File objects
"""
def get_folders(self, **kwargs) -> PaginatedList[Folder]:
"""
List folders for the user.
Parameters:
- sort: Sort folders by field
- order: Sort order
Returns:
Paginated list of Folder objects
"""
def create_folder(self, name: str, **kwargs) -> Folder:
"""
Create a folder in user's files.
Parameters:
- name: Folder name
- parent_folder_id: Parent folder ID (optional)
- locked: Whether folder is locked
- hidden: Whether folder is hidden
- position: Position in folder list
Returns:
Folder object
"""
def get_file(self, file_id, **kwargs) -> File:
"""Get a specific file by ID."""
def upload_file(self, file_path: str, **kwargs) -> File:
"""
Upload a file to user's files.
Parameters:
- file_path: Path to file to upload
- name: Custom name for the file
- parent_folder_id: Folder to upload to
Returns:
File object
"""Manage user's communication preferences and channels.
def get_communication_channels(self, **kwargs) -> PaginatedList[CommunicationChannel]:
"""
List communication channels for the user.
Returns:
Paginated list of CommunicationChannel objects (email, SMS, etc.)
"""
def create_communication_channel(self, communication_channel: dict, **kwargs) -> CommunicationChannel:
"""
Create a communication channel.
Parameters:
- communication_channel: Dictionary with channel attributes:
- address: Email address or phone number
- type: Channel type ('email', 'sms')
- token: Verification token (for SMS)
Returns:
CommunicationChannel object
"""Access user's calendar events and scheduling information.
def get_calendar_events_for_user(self, **kwargs) -> PaginatedList[CalendarEvent]:
"""
Get calendar events for the user.
Parameters:
- type: Filter by event type ('event', 'assignment')
- start_date: Start date for filtering events
- end_date: End date for filtering events
- undated: Include undated events
- all_events: Include events from all contexts
- context_codes: Filter by specific contexts
Returns:
Paginated list of CalendarEvent objects
"""Manage observer relationships (parent-student connections).
def add_observee(self, observee, **kwargs) -> User:
"""
Add a user as an observee (for observer accounts).
Parameters:
- observee: User object or user ID to observe
- root_account_id: Root account for the relationship
Returns:
User object of the observee
"""
def get_observees(self, **kwargs) -> PaginatedList[User]:
"""
List users being observed by this user.
Parameters:
- include: Additional data ('avatar_url', etc.)
Returns:
Paginated list of User objects being observed
"""
def remove_observee(self, observee, **kwargs) -> User:
"""
Remove an observee relationship.
Parameters:
- observee: User object or user ID to stop observing
Returns:
User object of the removed observee
"""
def get_observers(self, **kwargs) -> PaginatedList[User]:
"""
List users observing this user.
Returns:
Paginated list of User objects (observers)
"""Manage user's content migrations and imports.
def create_content_migration(self, migration_type: str, **kwargs) -> ContentMigration:
"""
Create a content migration for the user.
Parameters:
- migration_type: Type of migration ('zip_file_importer', 'course_copy_importer', etc.)
- pre_attachment: File attachment for migration
- settings: Migration-specific settings
Returns:
ContentMigration object
"""
def get_content_migrations(self, **kwargs) -> PaginatedList[ContentMigration]:
"""List content migrations for the user."""Access user activity data and analytics information.
def get_page_views(self, **kwargs) -> PaginatedList[PageView]:
"""
Get page view data for the user.
Parameters:
- start_time: Start date for page views
- end_time: End date for page views
Returns:
Paginated list of PageView objects
"""
def get_authentication_events(self, **kwargs) -> PaginatedList[AuthenticationEvent]:
"""
Get authentication events for the user.
Parameters:
- start_time: Start date for events
- end_time: End date for events
Returns:
Paginated list of AuthenticationEvent objects
"""Manage user's ePortfolios.
def get_eportfolios(self, **kwargs) -> PaginatedList[EPortfolio]:
"""List ePortfolios for the user."""
def moderate_all_eportfolios(self, **kwargs) -> dict:
"""Moderate all ePortfolios for the user (admin function)."""Manage usage rights for user's content.
def set_usage_rights(self, file_ids: list, usage_rights: dict, **kwargs) -> UsageRights:
"""
Set usage rights for files.
Parameters:
- file_ids: List of file IDs
- usage_rights: Dictionary with usage rights information:
- use_justification: Justification for use
- legal_copyright: Copyright information
- license: License type
Returns:
UsageRights object
"""
def remove_usage_rights(self, file_ids: list, **kwargs) -> UsageRights:
"""
Remove usage rights from files.
Parameters:
- file_ids: List of file IDs to remove rights from
Returns:
UsageRights object
"""Extended functionality for the currently authenticated user.
class CurrentUser(User):
def get_bookmarks(self, **kwargs) -> PaginatedList[Bookmark]:
"""List bookmarks for the current user."""
def create_bookmark(self, **kwargs) -> Bookmark:
"""
Create a bookmark.
Parameters:
- name: Bookmark name
- url: Bookmark URL
- position: Position in bookmark list
- data: Additional bookmark data
Returns:
Bookmark object
"""
def get_graded_submissions(self, **kwargs) -> PaginatedList[Submission]:
"""Get graded submissions for the current user."""
def list_user_logins(self, **kwargs) -> PaginatedList[Login]:
"""List login methods for the current user."""
def edit_user_login(self, login_id, **kwargs) -> Login:
"""Edit a login method for the current user."""from canvasapi import Canvas
canvas = Canvas("https://canvas.example.com", "your-token")
user = canvas.get_user(12345)
# Get and update user profile
profile = user.get_profile()
print(f"User: {profile['name']} ({profile['primary_email']})")
# Update user information
updated_user = user.edit(
name="John Smith",
short_name="John",
email="john.smith@example.com",
bio="Computer Science student interested in AI and machine learning."
)# Get all courses for a user
courses = user.get_courses(
enrollment_state='active',
include=['needs_grading_count', 'total_scores']
)
for course in courses:
print(f"Course: {course.name}")
# Get assignments for this course
assignments = user.get_user_assignments(course)
for assignment in assignments:
print(f" Assignment: {assignment.name} (Due: {assignment.due_at})")
# Get missing submissions
missing = user.get_missing_submissions(include=['course'])
for assignment in missing:
print(f"Missing: {assignment.name} in {assignment.course['name']}")# Get user's files
files = user.get_files(
search_term="assignment",
sort="created_at",
order="desc"
)
for file in files:
print(f"File: {file.display_name} ({file.size} bytes)")
# Create a folder and upload a file
folder = user.create_folder("My Assignments")
new_file = user.upload_file(
"/path/to/assignment.pdf",
parent_folder_id=folder.id
)# For observer accounts - add a student to observe
observer = canvas.get_user(observer_id)
student = canvas.get_user(student_id)
# Add observing relationship
observer.add_observee(student)
# Get all students being observed
observees = observer.get_observees()
for student in observees:
print(f"Observing: {student.name}")
# Get the student's courses
courses = student.get_courses(enrollment_state='active')
for course in courses:
print(f" Course: {course.name}")# Get current communication channels
channels = user.get_communication_channels()
for channel in channels:
print(f"Channel: {channel.address} ({channel.type})")
# Add a new email address
new_channel = user.create_communication_channel({
'address': 'alternate@example.com',
'type': 'email'
})Install with Tessl CLI
npx tessl i tessl/pypi-canvasapi