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.
Fund package maintenance!
jjuanrivvera99
Requires
- php: ^8.1
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^7.3
- psr/log: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2025-08-01 21:18:37 UTC
README

Canvas LMS Kit
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
- Installation
- Configuration
- Usage Examples
- Supported APIs
- Advanced Features
- Testing
- Contributing
- Support
๐ 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
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Write tests for your changes
- Ensure all tests pass (
composer check
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ฌ Support
|
|
|
Resources
- ๐ Wiki Documentation - Comprehensive guides
- ๐ API Reference - Detailed API docs
- ๐ฌ GitHub Discussions - Community forum
- ๐ง Email: jjuanrivvera@gmail.com
โญ 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.
Built with โค๏ธ by the Canvas LMS Kit community