Python SDK Cheatsheet
A quick debrief of the most important commands to know when using the codePost Python SDK
For more details on using the codePost Python SDK checkout the following resources:
Configuration
# Install codepost SDK
# pip install codepost
import codepost
# Find your API Key on your codePost Admin Dashboard
codepost.configure_api_key("YOUR_API_KEY")
courses = codepost.course.list_available()
courses = codepost.course.list_available(name="CS101")
Filtering Lazy Lists
course = codepost.course.list_available()[0]
assignment = course.assignments.by_name('Hello World')
rubricCategory = assignment.rubricCategories.by_name('Style')
section = course.sections.by_name('Section 1')
Basic CRUD
course = codepost.course.list_available()[0]
assignment = course.assignments.by_name('Hello World')
# Create a submission
submission = codepost.submission.create(assignment=assignment.id, students=['[email protected]'])
# Create a file and add it to the submission
file = codepost.file.create(name="hello.py", code="print('hello world')", extension="py", submission=submission.id)
# Just to demonstrate, retrieve the same submission
submission = codepost.submission.retrieve(id=submission.id)
# Create another file
file2 = codepost.file.create(name="loops.py", code="print('loops')", extension="py", submission=submission.id)
# Refresh the submission
submission.refresh()
# Update file code
file = submission.files.by_name('hello.py')
codepost.file.update(id=file.id, code="print('goodbye world')")
file.refresh()
# Delete the submission
submission.delete()
Get Roster
course = codepost.course.list_available()[0]
roster = codepost.roster.retrieve(id=course.id)
Get Submissions
course = codepost.course.list_available()[0]
assignment = course.assignments.by_name('Hello World')
# List all submissions for the assignment
submissions = assignment.list_submissions()
# Filter the submissions for the assignment
submissions = assignment.list_submissions(student='[email protected]')
submissions = assignment.list_submissions(grader='[email protected]')
Updated over 4 years ago