Package: ladok3
ladok3: Python wrapper for LADOK3 APIThis package provides a wrapper for the LADOK3 API used bystart.ladok.se. This makes it easy to automate reporting grades,
compute statistics etc.InstallationTo install, run:pipinstallladok3
sudocp$(find/-nameladok.bash)/etc/bash_completion.d
ladokloginIf you run the second line above, you'll get tab completion for theladokcommand when you use thebashshell.The third command above is to log in, you only do this once.An alternative to installing the package is to run theDocker image.dockerrun-itdbosk/ladok3/bin/bashOr simply adapt your own image.UsageThere are two ways to use the package: as a Python package or through the
command-line toolladok.On the command lineLet's assume that we have a student with personnummer 123456-1234.
Let's also assume that this student has taken a course with course code AB1234
and finished the module LAB1 on date 2021-03-15.
Then we can report this result like this:ladokreport123456-1234AB1234LAB1-d2021-03-15-fIf we use Canvas for all results, we can even report all results for a
course.pipinstallcanvaslms
canvaslmslogin
canvaslmsresults-cAB1234-ALAB1|ladokreport-vThecanvaslms resultscommand will export the results in CSV format, this
will be piped toladok reportthat can read it and report it in bulk.As a Python packageTo use the package, it's just to import the package as usual.importladok3ls=ladok3.kth.LadokSession("user","password")student=ls.get_student("123456-1234")course_participation=student.courses(code="AB1234")[0]forresultincourse_participation.results():print(f"{course_participation.code}{result.component}: "f"{result.grade}({result.date})")component_result=course_participation.results(component="LAB1")[0]component_result.set_grade("P","2021-03-15")component_result.finalize()More documentationThere are more detailed usage examples in the details documentation that can be
round with thereleasesand in theexamplesdirectory.The examplesThere are some examples that can be found in theexamplesdirectory:example_LadokSession.pyjust shows how to establish a session.example_Course.pyshows course data related examples.example_Student.pyshows student data related examples.prgi.pyshows how to transfer grades from KTH Canvas to LADOK.statsdata.pyshows how to extract data for doing statistics for a course
and the students' results.We also have a few more examples described in the sections below.canvas_ladok3_spreadsheet.pyPurpose: Use the data in a Canvas course room together with the data from Ladok3 to create a spreadsheet of students in the course
and include their Canvas user_id, name, Ladok3 Uid, program_code, program name, etc.Note that the course_id can be given as a numeric value or a string which will be matched against the courses in the user's dashboard cards. It will first match against course codes, then short name, then original names.Input:canvas_ladok3_spreadsheet.py canvas_course_idAdd the "-T" flag to run in the Ladok test environment.Output: outputs a file ('users_programs-COURSE_ID.xlsx) containing a spreadsheet of the users informationcanvas_ladok3_spreadsheet.py 12162

canvas_ladok3_spreadsheet.py -t 'II2202 HT20-1'ladok3_course_instance_to_spreadsheet.pyPurpose: Use the data in Ladok3 together with the data from Canvas to create a spreadsheet of students in a course
instance and include their Canvas user_id (or "not in Canvas" if they do not have a Canvas user_id), name, Ladok3 Uid, program_code, program name, etc.Note that the course_id can be given as a numeric value or a string which will be matched against the courses in the user's dashboard cards. It will first match against course codes, then short name, then original names.Input:ladok3_course_instance_to_spreadsheet.py course_code course_instanceorladok3_course_instance_to_spreadsheet.py canvas_course_idor./ladok3_course_instance_to_spreadsheet.py course_codeOptionally include their personnumber with the flag -p or --personnumbersAdd the "-T" flag to run in the Ladok test environment.Output: outputs a file ('users_programs-instance-COURSE_INSTANCE.xlsx) containing a spreadsheet of the users information# for II2202 the P1 instance in 2019 the course instance is 50287
ladok3_course_instance_to_spreadsheet.py II2202 50287or# Canvas course_id for II2202 in P1 is 20979
ladok3_course_instance_to_spreadsheet.py 20979or# P1P2 is a nickname on a dashboard card for II2202 duing P1 and P2
./ladok3_course_instance_to_spreadsheet.py P1P2canvas_students_missing_integration_ids.pyPurpose: Use the data in a Canvas course room to create a spreadsheet of students in the course who are missing an integration ID.Input:canvas_students_missing_integration_ids.py canvas_course_idOutput: outputs a file ('users_without_integration_ids-COURSE_ID.xlsx) containing a spreadsheet of the users informationcl_user_info.pyPurpose: Use the data in a Canvas course room together with the data from Ladok3 to find information about a user.Input:Input 
cl_user_info.py Canvas_user_id|KTHID|Ladok_id [course_id]The course_id can be a Canvas course_idorif you have dashboard cards, you can specific a course code, a nickname, unique part of the short name or original course name.Add the "-k" or '--kthid' flag to get the KTHID (i.e., the 'sis_user_id) you need to specify a course_id for a course (where this user is a teacher or student) on the command line.Add the "-T" flag to run in the Ladok test environment.If you know the Ladok_id, i.e., the integration_id - then you do not need to specify a course_id.The program can also take an argument in the formhttps://canvas.kth.se/courses/course_id/users/user_idthis is the URL when you are on a user's page in a course.Output:from Canvas: sortable name, user_id, and integration_idif you specified a course_id, you will also get KTHID and login_idfrom Ladok:  pnr (personnumber) and [program_code, program_name, specialization/track code, admissions info]