jjuanrivvera/canvas-lms-kit

The most comprehensive PHP SDK for Canvas LMS API. Production-ready with 90% API coverage, rate limiting, and full test coverage.


README

Canvas LMS Kit

Canvas LMS Kit

Latest Version Total Downloads CI PHP Version License

The most comprehensive PHP SDK for Canvas LMS API. Production-ready with 90% API coverage.

โœจ Why Canvas LMS Kit?

  • ๐Ÿš€ Production Ready: Rate limiting, middleware support, battle-tested
  • ๐Ÿ“š Comprehensive: 21 Canvas APIs fully implemented (90% coverage)
  • ๐Ÿ›ก๏ธ Type Safe: Full PHP 8.1+ type declarations and PHPStan level 6
  • ๐Ÿ”ง Developer Friendly: Intuitive Active Record pattern - just pass arrays!
  • ๐Ÿ“– Well Documented: Extensive examples, guides, and API reference
  • โšก Performance: Built-in pagination, caching support, and optimized queries

๐ŸŽฏ Quick Start

use CanvasLMS\Config;
use CanvasLMS\Api\Courses\Course;

Config::setApiKey('your-api-key');
Config::setBaseUrl('https://canvas.instructure.com');

// It's that simple!
$courses = Course::fetchAll();
foreach ($courses as $course) {
    echo $course->name . "\n";
}

๐Ÿ“‘ Table of Contents

๐Ÿ“‹ Requirements

  • PHP 8.1 or higher
  • Composer
  • Canvas LMS API token
  • Extensions: json, curl, mbstring

๐Ÿ“ฆ Installation

composer require jjuanrivvera/canvas-lms-kit

โš™๏ธ Configuration

use CanvasLMS\Config;

// Basic configuration
Config::setApiKey('your-api-key');
Config::setBaseUrl('https://canvas.instructure.com');

// Optional: Set account ID for scoped operations
Config::setAccountId(1);

// Optional: Configure middleware
Config::setMiddleware([
    'retry' => ['max_attempts' => 3],
    'rate_limit' => ['wait_on_limit' => true],
]);

๐Ÿ’ก Usage Examples

Working with Courses

use CanvasLMS\Api\Courses\Course;

// List all courses
$courses = Course::fetchAll();

// Find a specific course
$course = Course::find(123);

// Create a new course - just pass an array!
$course = Course::create([
    'name' => 'Introduction to PHP',
    'course_code' => 'PHP101',
    'start_at' => '2025-02-01T00:00:00Z'
]);

// Update a course
$course->update([
    'name' => 'Advanced PHP Programming'
]);

// Delete a course
$course->delete();

Managing Assignments

use CanvasLMS\Api\Assignments\Assignment;

// Create an assignment - simple array syntax
$assignment = Assignment::create([
    'course_id' => 123,
    'name' => 'Final Project',
    'description' => 'Build a web application',
    'points_possible' => 100,
    'due_at' => '2025-03-15T23:59:59Z',
    'submission_types' => ['online_upload', 'online_url']
]);

// Grade submissions
$submission = $assignment->getSubmission($studentId);
$submission->grade([
    'posted_grade' => 95,
    'comment' => 'Excellent work!'
]);

File Uploads

use CanvasLMS\Api\Files\File;

// Upload a file to a course
$file = File::upload([
    'course_id' => 123,
    'file_path' => '/path/to/document.pdf',
    'name' => 'Course Syllabus.pdf',
    'parent_folder_path' => 'course_documents'
]);

๐Ÿ“Š Supported APIs

โœ… Currently Implemented (21 APIs - 90% Coverage)

๐Ÿ“š Core Course Management
  • โœ… Courses - Full CRUD operations
  • โœ… Modules - Content organization
  • โœ… Module Items - Individual content items
  • โœ… Sections - Course sections
  • โœ… Tabs - Navigation customization
  • โœ… Pages - Wiki-style content
๐Ÿ‘ฅ Users & Enrollment
  • โœ… Users - User management
  • โœ… Enrollments - Course enrollments
  • โœ… Admin/Account - Administrative functions
๐Ÿ“ Assessment & Grading
  • โœ… Assignments - Assignment management
  • โœ… Quizzes - Quiz creation and management
  • โœ… Quiz Submissions - Student attempts
  • โœ… Submissions - Assignment submissions
  • โœ… Submission Comments - Feedback
  • โœ… Rubrics - Grading criteria
๐Ÿ’ฌ Communication & Collaboration
  • โœ… Discussion Topics - Forums and discussions
  • ๐Ÿ”„ Announcements - Course announcements (coming soon)
  • ๐Ÿ”„ Groups - Student groups (coming soon)
๐Ÿ”ง Tools & Integration
  • โœ… Files - File management
  • โœ… External Tools - LTI integrations
  • โœ… Module Assignment Overrides - Custom dates
  • โœ… Calendar Events - Event management
  • โœ… Appointment Groups - Scheduling
  • โœ… Progress - Async operation tracking

๐Ÿš€ Advanced Features

Production-Ready Middleware

// The SDK automatically handles rate limiting and retries
$course = Course::find(123); // Protected by middleware

// Canvas API Rate Limiting (3000 requests/hour)
// โœ… Automatic throttling when approaching limits
// โœ… Smart backoff strategies
// โœ… Transparent to your application

Multi-Tenant Support

// Manage multiple Canvas instances
Config::setContext('production');
$prodCourse = Course::find(123);

Config::setContext('test');
$testCourse = Course::find(456);

Pagination Support

// Automatic pagination handling
$allCourses = Course::fetchAll(); // Fetches ALL pages automatically

// Manual pagination control
$paginator = Course::fetchAllPaginated(['per_page' => 50]);
foreach ($paginator as $page) {
    foreach ($page as $course) {
        // Process each course
    }
}

Relationship Methods

// Efficient relationship loading
$course = Course::find(123);
$students = $course->getStudents();
$assignments = $course->getAssignments();
$modules = $course->getModules();

๐Ÿงช Testing

# Using Docker (recommended)
docker compose exec php composer test
docker compose exec php composer check  # Run all checks

# Local development
composer test
composer cs-fix   # Fix coding standards
composer phpstan  # Static analysis

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guidelines.

Quick Contribution Guide

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Write tests for your changes
  4. Ensure all tests pass (composer check)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ’ฌ Support

Report a Bug Request Feature Ask Question

Resources

โญ Show Your Support

If you find this project helpful, please consider giving it a star on GitHub! It helps others discover the project and motivates continued development.

Star History Chart

Built with โค๏ธ by the Canvas LMS Kit community