### Schoolopy API Method Pattern Example Source: https://github.com/erikboesen/schoolopy/blob/master/README.rst Demonstrates a common pattern for interacting with Schoology API endpoints using the Schoolopy library. This pattern applies to various 'realm' types like district, school, user, section, or group, and methods such as get, create, update, and delete for objects like 'event'. ```python # Example for 'event' object within a realm # sc.get_events(realm_id=) # sc.get_[realm]_events([realm]_id) # sc.create_event(event, [realm]_id=) # sc.create_[realm]_event(event, [realm]_id) # sc.get_event(event_id, [realm]_id=) # sc.update_event(event, event_id, [realm]_id=) # sc.update_[realm]_event(event, event_id, [realm]_id) # sc.delete_event(event_id, [realm]_id=) # sc.delete_[realm]_event(event_id, [realm]_id) ``` -------------------------------- ### Python: Get User Information Source: https://context7.com/erikboesen/schoolopy/llms.txt Demonstrates retrieving user data using the Schoolopy library. It shows how to fetch information for the currently authenticated user and specific users by their ID. It also includes an example of fetching all users, with options for pagination and filtering inactive users. ```python import schoolopy sc = schoolopy.Schoology(schoolopy.Auth(key, secret)) # Get current user info me = sc.get_me() print(f"Name: {me.name_display}") print(f"Email: {me.primary_email}") print(f"Role: {me.role_name}") # Get specific user by ID user = sc.get_user(user_id=12345) print(f"User: {user.name_first} {user.name_last}") print(f"School ID: {user.school_id}") # Get all users (paginated) sc.limit = 50 users = sc.get_users() for user in users: print(f"{user.uid}: {user.name_display}") # Get inactive users inactive_users = sc.get_users(inactive=True) ``` -------------------------------- ### Python: Get Assignments Source: https://context7.com/erikboesen/schoolopy/llms.txt Provides examples for retrieving assignment data from Schoology course sections. The code demonstrates fetching all assignments within a section, including attachments, and retrieving a specific assignment by its ID. It also shows how to access assignment details like title, due date, max points, and associated files. ```python import schoolopy sc = schoolopy.Schoology(schoolopy.Auth(key, secret)) section_id = 123456 # Get all assignments in a section assignments = sc.get_assignments( section_id=section_id, with_attachments=True ) for assignment in assignments: print(f"{assignment.title}") print(f" Due: {assignment.due}") print(f" Max points: {assignment.max_points}") print(f" Type: {assignment.type}") # Get specific assignment assignment = sc.get_assignment( section_id=section_id, assignment_id=789012, with_attachments=True ) print(f"Assignment: {assignment.title}") print(f"Description: {assignment.description}") if 'attachments' in assignment: for attachment in assignment.attachments.files: print(f" File: {attachment.filename}") ``` -------------------------------- ### Retrieve Assignment Submissions with Schoolopy Source: https://context7.com/erikboesen/schoolopy/llms.txt This Python code demonstrates retrieving assignment submissions, including attachments, using the Schoolopy library. It shows how to get all submissions for an assignment and how to filter submissions for a specific user. Dependencies include the `schoolopy` library and authentication credentials. ```python import schoolopy sc = schoolopy.Schoology(schoolopy.Auth(key, secret)) section_id = 123456 assignment_id = 789012 # Get all submissions for an assignment submissions = sc.get_assignment_submissions( section_id=section_id, assignment_id=assignment_id, with_attachments=True ) for submission in submissions: print(f"User {submission.uid}: Revision {submission.revision}") print(f" Submitted: {submission.created}") print(f" Late: {submission.late}") if 'attachments' in submission: for file in submission.attachments.files.file: print(f" File: {file.filename}") # Get submissions for specific user user_submissions = sc.get_user_assignment_submissions( section_id=section_id, assignment_id=assignment_id, user_id=12345, with_attachments=True ) latest = user_submissions[0] print(f"Latest submission: {latest.created}") print(f"Number of revisions: {len(user_submissions)}") ``` -------------------------------- ### Python: Get Sections and Courses Source: https://context7.com/erikboesen/schoolopy/llms.txt Illustrates how to access course sections and related data within Schoology. The code shows fetching all sections for a user, retrieving a specific section by its ID, and obtaining enrollments within a section. It also covers fetching sections for a particular user. ```python import schoolopy sc = schoolopy.Schoology(schoolopy.Auth(key, secret)) # Get all sections for authenticated user sections = sc.get_sections() for section in sections: print(f"{section.section_title} ({section.course_title})") print(f" Section ID: {section.id}") print(f" Course Code: {section.section_code}") # Get specific section by ID section = sc.get_section(section_id=123456) print(f"Section: {section.section_title}") print(f"Grading periods: {section.grading_periods}") # Get sections for specific user user_sections = sc.get_user_sections(user_id=12345) # Get enrollments in a section enrollments = sc.get_section_enrollments(section_id=123456) for enrollment in enrollments: print(f"User {enrollment.uid}: {enrollment.name_display}") print(f" Role: {enrollment.admin}") ``` -------------------------------- ### Get Student Grades with Schoolopy Source: https://context7.com/erikboesen/schoolopy/llms.txt This section shows how to retrieve student grades using the Schoolopy library. It covers fetching grades for a user across all sections, for a specific section, and how to retrieve grading period information. Requires the `schoolopy` library and authentication. ```python import schoolopy sc = schoolopy.Schoology(schoolopy.Auth(key, secret)) # Get grades for a user across all sections user_id = 12345 grades = sc.get_user_grades(user_id=user_id) for section_grade in grades: print(f"Section: {section_grade.section_title}") print(f" Grade: {section_grade.final_grade[0].grade}") print(f" Comment: {section_grade.final_grade[0].comment}") # Get grades for specific section section_grades = sc.get_user_grades_by_section( user_id=user_id, section_id=123456 ) for grade in section_grades: if 'period' in grade: for period in grade.period: print(f"Period {period.period_id}: {period.grade}") # Get grading periods periods = sc.get_grading_periods() for period in periods: print(f"{period.title}: {period.start} to {period.end}") ``` -------------------------------- ### Python: Authenticate with Three-Legged OAuth Source: https://context7.com/erikboesen/schoolopy/llms.txt Guides through the three-legged OAuth flow for web applications, enabling user authorization. It involves requesting an authorization URL, prompting the user to authorize, and then completing the authorization to obtain an authenticated Schoology client. Error handling for authorization failure is included. ```python import schoolopy import webbrowser # Initialize three-legged OAuth DOMAIN = 'https://yourschool.schoology.com' auth = schoolopy.Auth( consumer_key='your_key', consumer_secret='your_secret', three_legged=True, domain=DOMAIN ) # Get authorization URL url = auth.request_authorization(callback_url='https://yourapp.com/callback') if url: webbrowser.open(url) input('Press enter after authorizing...') # Complete authorization if not auth.authorize(): raise SystemExit('Authorization failed') # Create authenticated client sc = schoolopy.Schoology(auth) user = sc.get_me() print(f"Successfully authorized: {user.name_display}") ``` -------------------------------- ### Work with Pages and Content in Schoolopy Source: https://context7.com/erikboesen/schoolopy/llms.txt Shows how to interact with course pages, folders, and downloadable content within Schoology using the Schoolopy Python API. This includes fetching pages with their content and attachments, retrieving specific pages, accessing folder structures, and downloading files. ```python import schoolopy sc = schoolopy.Schoology(schoolopy.Auth(key, secret)) section_id = 123456 # Get all pages in a section pages = sc.get_pages( section_id=section_id, with_content=True, with_attachments=True ) for page in pages: print(f"Page: {page.title}") print(f" Type: {page.type}") if 'body' in page: print(f" Content length: {len(page.body)} chars") # Get specific page page = sc.get_section_page( page_id=789012, section_id=section_id, with_attachments=True ) print(f"Title: {page.title}") print(f"Body: {page.body}") # Get course folder structure folder = sc.get_section_folder( section_id=section_id, folder_id=111222 ) print(f"Folder: {folder.title}") # Download a file file_url = 'https://api.schoology.com/v1/documents/12345' response = sc.get_file(url=file_url) with open('downloaded_file.pdf', 'wb') as f: f.write(response.content) print(f"Downloaded file, size: {len(response.content)} bytes") ``` -------------------------------- ### Manage Enrollments in Schoolopy Source: https://context7.com/erikboesen/schoolopy/llms.txt Illustrates how to manage user enrollments within Schoology sections using the Schoolopy Python library. This includes retrieving existing enrollments, creating single or bulk enrollments, and deleting enrollments. ```python import schoolopy sc = schoolopy.Schoology(schoolopy.Auth(key, secret)) section_id = 123456 # Get enrollments enrollments = sc.get_section_enrollments(section_id=section_id) for enrollment in enrollments: print(f"{enrollment.name_display} ({enrollment.uid})") print(f" Role: {enrollment.admin}") print(f" Status: {enrollment.status}") # Create single enrollment new_enrollment = schoolopy.Enrollment({ 'uid': 12345, 'admin': 0, # 0=student, 1=teacher, 2=admin 'status': 1 # 1=active }) created = sc.create_section_enrollment( enrollment=new_enrollment, section_id=section_id ) # Bulk create enrollments enrollments_list = [ schoolopy.Enrollment({'uid': 11111, 'admin': 0, 'status': 1}), schoolopy.Enrollment({'uid': 22222, 'admin': 0, 'status': 1}), schoolopy.Enrollment({'uid': 33333, 'admin': 0, 'status': 1}) ] created_bulk = sc.create_section_enrollments( enrollments=enrollments_list, section_id=section_id ) print(f"Created {len(created_bulk)} enrollments") # Delete enrollment sc.delete_section_enrollment( enrollment_id=789012, section_id=section_id ) ``` -------------------------------- ### Create New Assignment with Schoolopy Source: https://context7.com/erikboesen/schoolopy/llms.txt This snippet demonstrates how to create a new assignment in Schoology using the Schoolopy library. It involves initializing an Assignment object with details like title, description, due date, and max points, then using the `create_assignment` method. Dependencies include the `schoolopy` library and a valid Schoology authentication object. ```python import schoolopy new_assignment = schoolopy.Assignment({ 'title': 'Homework 5', 'description': 'Complete problems 1-10', 'due': '2025-10-20 23:59:00', 'max_points': 100, 'type': 'assignment' }) created = sc.create_assignment(new_assignment, section_id=section_id) print(f"Created assignment ID: {created.id}") ``` -------------------------------- ### Python: Authenticate with Two-Legged OAuth Source: https://context7.com/erikboesen/schoolopy/llms.txt Authenticates with Schoology using two-legged OAuth, suitable for single-user applications. It requires API keys loaded from a configuration file and initializes the Schoology client. The snippet demonstrates setting request limits and fetching authenticated user details. ```python import schoolopy import yaml # Load API credentials with open('config.yml', 'r') as f: cfg = yaml.load(f) # Initialize with two-legged OAuth (default) auth = schoolopy.Auth(cfg['key'], cfg['secret']) sc = schoolopy.Schoology(auth) # Set result limits sc.limit = 20 # Return max 20 objects per request sc.start = 0 # Start at offset 0 # Access API user = sc.get_me() print(f"Authenticated as: {user.name_display}") print(f"User ID: {user.uid}") ``` -------------------------------- ### Two-Legged Authentication with Schoolopy Source: https://github.com/erikboesen/schoolopy/blob/master/README.rst Sets up a two-legged authentication flow for the Schoolopy API. This method is suitable for applications used by a single user who can manage API keys. It requires a consumer key and secret obtained from Schoology. ```python # Two-legged sc = schoolopy.Schoology(schoolopy.Auth(key, secret)) sc.get_feed() # etc. ``` -------------------------------- ### Import Schoolopy Library Source: https://github.com/erikboesen/schoolopy/blob/master/README.rst Initial step to import the schoolopy library for use in your Python script. No external dependencies are needed for this basic import. ```python import schoolopy ``` -------------------------------- ### Send and Manage Messages with Schoolopy Source: https://context7.com/erikboesen/schoolopy/llms.txt This Python code covers sending messages and managing the inbox/sent messages using the Schoolopy library. It demonstrates sending a message using a helper function and manually creating a message object. It also shows how to retrieve inbox messages, sent messages, and thread details. Requires `schoolopy` and authentication. ```python import schoolopy sc = schoolopy.Schoology(schoolopy.Auth(key, secret)) # Send message using helper function message = sc.send_message( subject='Meeting Tomorrow', content='Remember we have a team meeting at 3pm.', user_ids=['12345', '67890', '11111'] ) print(f"Message sent, ID: {message.id}") # Create message manually new_message = schoolopy.Message({ 'subject': 'Assignment Reminder', 'message': 'Don\'t forget the homework is due Friday.', 'recipient_ids': '12345,67890' # Comma-separated string }) sent = sc.create_message(new_message) # Get inbox messages inbox = sc.get_inbox_messages() for thread in inbox: print(f"Subject: {thread.subject}") print(f" From: {thread.author_name}") print(f" Date: {thread.last_updated}") # Get sent messages sent_messages = sc.get_sent_messages() # Get message thread details thread_id = 123456 messages = sc.get_message(message_id=thread_id) for msg in messages: print(f"{msg.author_name}: {msg.message}") ``` -------------------------------- ### Three-Legged Authentication with Schoolopy Source: https://github.com/erikboesen/schoolopy/blob/master/README.rst Implements a three-legged authentication flow for the Schoolopy API, suitable for web applications. This process involves requesting authorization, redirecting the user, and then authorizing the application. It requires a consumer key, secret, and the school's Schoology domain. ```python # Three-legged auth = schoolopy.Auth(key, secret, three_legged=True, domain='https://schoology.com') # Replace URL with that of your school's Schoology url = auth.request_authorization() # Redirect user to that URL as appropriate for your application. Once user has performed action, continue. if not auth.authorize(): raise SystemExit('User not authorized!') sc = schoolopy.Schoology(auth) ``` -------------------------------- ### Access User Feed with Schoolopy Source: https://context7.com/erikboesen/schoolopy/llms.txt This snippet illustrates how to fetch the authenticated user's home feed updates using the Schoolopy library. It includes retrieving the most recent updates, displaying author information, post content, likes, and comments. It also shows how to retrieve a specific update from a section. Requires `schoolopy` and authentication. ```python import schoolopy sc = schoolopy.Schoology(schoolopy.Auth(key, secret)) sc.limit = 10 # Get 10 most recent updates # Get feed updates feed = sc.get_feed() for update in feed: user = sc.get_user(update.uid) print(f"By: {user.name_display}") print(f"Posted: {update.created}") # Truncate long posts body = update.body[:100].replace('\n', ' ') if len(update.body) > 100: body += '...' print(f"Content: {body}") print(f"Likes: {update.likes}") print(f"Comments: {update.num_comments}") print() # Get specific update from a section update = sc.get_section_update( update_id=456789, section_id=123456 ) ``` -------------------------------- ### Manage Calendar Events with Schoolopy Source: https://context7.com/erikboesen/schoolopy/llms.txt This Python snippet demonstrates managing calendar events within Schoology using the Schoolopy library. It includes retrieving events for a specific section and creating a new event in a section. The code requires the `schoolopy` library and valid authentication credentials. ```python import schoolopy sc = schoolopy.Schoology(schoolopy.Auth(key, secret)) # Get section events section_id = 123456 events = sc.get_section_events(section_id=section_id) for event in events: print(f"{event.title}: {event.start}") print(f" All day: {event.all_day}") print(f" Location: {event.location}") # Create event in a section new_event = schoolopy.Event({ 'title': 'Final Exam', 'description': 'Chapters 1-10', 'start': '2025-12-15 09:00:00', 'end': '2025-12-15 11:00:00', 'all_day': 0, 'location': 'Room 205' }) created_event = sc.create_section_event( event=new_event, section_id=section_id ) print(f"Event created, ID: {created_event.id}") ``` -------------------------------- ### Manage User Events in Schoolopy Source: https://context7.com/erikboesen/schoolopy/llms.txt Demonstrates how to retrieve, update, and delete user events using the Schoolopy library. This involves calling specific methods on the Schoology API object with relevant IDs and event data. ```python # Get user events user_events = sc.get_user_events(user_id=12345) # Update event event.title = 'Final Exam (Updated)' sc.update_section_event( event=event, event_id=event.id, section_id=section_id ) # Delete event sc.delete_section_event(event_id=789012, section_id=section_id) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.