To keep third-party learning apps in sync with your student information system (SIS), export rosters from the SIS as CSV files, use a short Python script to check the data and build a separate file set for each app with only the students and fields that app needs, compare it with the last sync, and only then send it. Python’s built-in csv module is enough for all of it; no extra packages are needed.

A typical district runs dozens of third-party apps: a reading program in the elementary schools, a math platform in the middle schools, a typing tutor, an assessment tool, a library system. Every one of them needs to know which students and teachers exist and which classes they’re in. When those rosters are uploaded by hand, they drift: new students wait days for accounts, students who left keep access, and someone’s spreadsheet ends up holding birthdates and special education flags that the app never needed.

This guide shows how to treat app rostering as a data management task. You’ll walk through a complete Python script that reads SIS exports, catches bad rows, builds per-app CSV files, reports what changed, and refuses to run when an export looks broken.

Why Rostering Is a Data Management Problem

Integrating an app is more than creating accounts once. The roster changes every day as students enroll, withdraw, change schedules, or change names, and every app needs those changes. Doing it by hand causes predictable problems:

  • Stale accounts. A student who withdrew in October can still log in to an app in March, which is both a privacy and a licensing problem.
  • Oversharing. It’s easy to send the whole SIS export, including birthdates, home language, or program flags, when the app only needs a name, a grade, and a class.
  • Different formats. One app wants First Name, another wants given_name. One wants grades as K, another as 0.
  • No record. Without a log, nobody can answer “when did this student’s account get created?” or “what did we send to this vendor?”

A small script fixes all four: it applies the same rules on every run, sends each app only what its configuration allows, and writes down what it did.

Rostering Options and Where a Script Fits

Before writing code, check what each app supports. Most districts end up with a mix of these:

OptionHow it worksGood fit
Rostering platform (such as Clever or ClassLink)Connects to the SIS once and shares rosters with every app that supports itApps that support the platform; usually the first choice
OneRosterA 1EdTech standard for roster data, as CSV files or an APIApps and SIS products that support it
Vendor CSV uploadThe vendor gives you a template and an upload page or SFTP folderSmaller or specialized apps without platform support

A script like the one in this guide fills the third row, and it’s also useful for checking data before it reaches any platform. If an app supports your rostering platform, use that instead of building a custom feed. Always follow each vendor’s own template and delivery instructions, since column names and formats vary.

The Workflow

Every run of the sync follows the same steps:

  1. Export students, teachers, sections, and enrollments from the SIS as CSV files.
  2. Validate the rows and set aside any that are incomplete or wrong.
  3. Filter each app’s data down to its own schools, classes, and columns.
  4. Compare the new files with the files sent last time to see what changed.
  5. Stop if the changes look too big to be real.
  6. Write the files, and log the run.
  7. Deliver the files to the vendor, usually by SFTP.

The script below does steps 2 to 6. Steps 1 and 7 depend on your SIS and your vendors, and are covered at the end.

The Sample Data

The example district has two schools: 101 (an elementary school) and 201 (a middle school). The SIS export has four files:

FileColumns
students.csvstudent_id, first_name, last_name, grade, school_id, email, birthdate, home_language, iep, status
teachers.csvteacher_id, first_name, last_name, school_id, email
sections.csvsection_id, school_id, course_name, subject, teacher_id
enrollments.csvsection_id, student_id

The district licenses two apps: a reading app for the elementary reading classes and a math app for the middle school math classes. Here’s the first export’s students.csv, with a few problems built in:

student_id,first_name,last_name,grade,school_id,email,birthdate,home_language,iep,status
100001,Sofía,Martínez,3,101,[email protected],2017-04-12,Spanish,N,active
100002,Liam,Johnson,3,101,[email protected],2017-09-03,English,N,active
100003,Emma,Garcia,3,101,[email protected],2017-01-22,English,Y,active
100004,Noah,Smith,4,101,[email protected],2016-06-30,English,N,active
100005,Ava,Hernández,4,101,[email protected],2016-11-08,Spanish,N,active
100006,Mateo,López,4,101,[email protected],2016-02-14,Spanish,Y,active
100007,Olivia,Brown,6,201,[email protected],2014-05-19,English,N,active
100008,Ethan,Davis,6,201,[email protected],2014-08-27,English,N,active
100009,Isabella,Wilson,7,201,[email protected],2013-03-15,English,N,active
100010,Lucas,Moore,7,201,[email protected],2013-12-01,English,N,active
100011,Mia,Taylor,7,201,[email protected],2013-07-09,English,Y,active
100012,Daniel,Reyes,6,201,[email protected],2014-10-04,Spanish,N,withdrawn
100013,Chloe,,6,201,[email protected],2014-01-25,English,N,active
100004,Noah,Smith,4,101,[email protected],2016-06-30,English,N,active
100014,Jacob,Young,13,201,[email protected],2014-09-12,English,N,active
100015,Emily,White,7,201,[email protected],2013-04-30,English,N,active

Follow along: the sample exports and the script are in the k12-roster-sync folder of the sample data repository. All names, IDs, and email addresses are made up. Run the script from inside that folder.

The Script

roster_sync.py uses only Python’s standard library:

"""
Roster sync: turn a student information system (SIS) export into
one set of CSV roster files per third-party app.

Usage:  python roster_sync.py sis_day1
"""

import csv
import sys
from datetime import datetime
from pathlib import Path

VALID_GRADES = {"K"} | {str(n) for n in range(1, 13)}
REQUIRED = ["student_id", "first_name", "last_name", "grade", "school_id", "status"]
STUDENT_EMAIL_DOMAIN = "@students.example.org"
MAX_REMOVE_SHARE = 0.2   # stop if more than 20% of an app's students would disappear
EXPORT_FOLDER = Path("exports")
LOG_FILE = Path("sync_log.csv")

# Each app gets only the schools, subjects, and columns it needs.
# student_columns maps the app's column name -> the SIS column name.
VENDORS = {
    "reading_app": {
        "schools": {"101"},
        "subjects": {"ELA"},
        "student_columns": {
            "Student ID": "student_id",
            "First Name": "first_name",
            "Last Name": "last_name",
            "Grade": "grade",
        },
    },
    "math_app": {
        "schools": {"201"},
        "subjects": {"Math"},
        "student_columns": {
            "sis_id": "student_id",
            "given_name": "first_name",
            "family_name": "last_name",
            "grade_level": "grade",
            "email": "email",
        },
    },
}


def read_csv(path):
    """Reads a CSV file into a list of dictionaries, trimming extra spaces."""
    # utf-8-sig also handles the hidden marker Excel adds to the start of UTF-8 files
    with open(path, newline="", encoding="utf-8-sig") as file:
        return [
            {key.strip(): (value or "").strip() for key, value in row.items()}
            for row in csv.DictReader(file)
        ]


def write_csv(path, rows, columns):
    """Writes a list of dictionaries to a CSV file with the given columns."""
    path.parent.mkdir(parents=True, exist_ok=True)
    with open(path, "w", newline="", encoding="utf-8") as file:
        writer = csv.DictWriter(file, fieldnames=columns)
        writer.writeheader()
        writer.writerows(rows)


def validate_students(rows):
    """Returns (active students by ID, list of problems found)."""
    students, problems, seen = {}, [], set()
    for line, row in enumerate(rows, start=2):   # line 1 is the header
        missing = [column for column in REQUIRED if not row.get(column)]
        if missing:
            problems.append(f"line {line}: {row.get('student_id')} is missing {', '.join(missing)}")
            continue
        student_id = row["student_id"]
        if student_id in seen:
            problems.append(f"line {line}: duplicate student_id {student_id}")
            continue
        seen.add(student_id)
        if row["grade"] not in VALID_GRADES:
            problems.append(f"line {line}: {student_id} has grade {row['grade']!r}")
            continue
        if row["email"] and not row["email"].endswith(STUDENT_EMAIL_DOMAIN):
            problems.append(f"line {line}: {student_id} has a non-district email")
            continue
        if row["status"] == "active":
            students[student_id] = row
    return students, problems


def build_export(config, students, teachers, sections, enrollments):
    """Returns the student, class, and enrollment rows for one app."""
    classes = [
        section for section in sections
        if section["school_id"] in config["schools"] and section["subject"] in config["subjects"]
    ]
    class_ids = {section["section_id"] for section in classes}
    links = [
        row for row in enrollments
        if row["section_id"] in class_ids and row["student_id"] in students
    ]
    enrolled = sorted({row["student_id"] for row in links})

    student_rows = [
        {app_col: students[sid][sis_col] for app_col, sis_col in config["student_columns"].items()}
        for sid in enrolled
    ]
    class_rows = [
        {
            "class_id": section["section_id"],
            "class_name": section["course_name"],
            "teacher_id": section["teacher_id"],
            "teacher_email": teachers[section["teacher_id"]]["email"],
        }
        for section in classes
    ]
    enrollment_rows = [{"class_id": row["section_id"], "student_id": row["student_id"]} for row in links]
    return student_rows, class_rows, enrollment_rows


def compare(old_rows, new_rows, key):
    """Returns the IDs that were added, changed, and removed since the last sync."""
    old = {row[key]: row for row in old_rows}
    new = {row[key]: row for row in new_rows}
    added = [k for k in new if k not in old]
    changed = [k for k in new if k in old and new[k] != old[k]]
    removed = [k for k in old if k not in new]
    return added, changed, removed


def log_sync(vendor, students, added, changed, removed, result):
    """Appends one line per app and run to sync_log.csv."""
    new_file = not LOG_FILE.exists()
    with open(LOG_FILE, "a", newline="", encoding="utf-8") as file:
        writer = csv.writer(file)
        if new_file:
            writer.writerow(["timestamp", "vendor", "students", "added", "changed", "removed", "result"])
        writer.writerow([datetime.now().isoformat(timespec="seconds"), vendor, students,
                         len(added), len(changed), len(removed), result])


def main(sis_folder):
    sis = Path(sis_folder)
    students, problems = validate_students(read_csv(sis / "students.csv"))
    teachers = {row["teacher_id"]: row for row in read_csv(sis / "teachers.csv")}
    sections = read_csv(sis / "sections.csv")
    enrollments = read_csv(sis / "enrollments.csv")

    print(f"SIS export: {len(students)} active students, problems found: {len(problems)}")
    for problem in problems:
        print("  SKIPPED", problem)

    for vendor, config in VENDORS.items():
        folder = EXPORT_FOLDER / vendor
        student_rows, class_rows, enrollment_rows = build_export(
            config, students, teachers, sections, enrollments)

        key = next(iter(config["student_columns"]))   # the app's ID column
        old_file = folder / "students.csv"
        old_rows = read_csv(old_file) if old_file.exists() else []
        added, changed, removed = compare(old_rows, student_rows, key)

        if old_rows and len(removed) > len(old_rows) * MAX_REMOVE_SHARE:
            print(f"{vendor}: STOPPED, {len(removed)} of {len(old_rows)} students would be "
                  "removed. Check the SIS export; the last files were kept.")
            log_sync(vendor, len(student_rows), added, changed, removed, "stopped")
            continue

        write_csv(folder / "students.csv", student_rows, list(config["student_columns"]))
        write_csv(folder / "classes.csv", class_rows,
                  ["class_id", "class_name", "teacher_id", "teacher_email"])
        write_csv(folder / "enrollments.csv", enrollment_rows, ["class_id", "student_id"])
        log_sync(vendor, len(student_rows), added, changed, removed, "ok")

        print(f"{vendor}: {len(student_rows)} students, {len(class_rows)} classes "
              f"(added {added or 'none'}, changed {changed or 'none'}, removed {removed or 'none'})")


if __name__ == "__main__":
    if len(sys.argv) != 2:
        sys.exit("Usage: python roster_sync.py <sis folder>")
    main(sys.argv[1])

How the Script Works

Reading CSV Files Safely

with open(path, newline="", encoding="utf-8-sig") as file:
    return [
        {key.strip(): (value or "").strip() for key, value in row.items()}
        for row in csv.DictReader(file)
    ]

csv.DictReader turns each row into a dictionary keyed by the header, so the code can say row["grade"] instead of row[3], and it keeps working if the SIS adds or reorders columns. Three details matter with school data:

  • newline="" is what the csv module documentation asks for, so quoted values with line breaks are read correctly.
  • encoding="utf-8-sig" reads UTF-8 files and also strips the invisible byte order mark Excel adds when it saves “CSV UTF-8”. Without it, the first column name becomes student_id and lookups fail.
  • .strip() removes stray spaces, a common cause of “duplicate” students who differ only by a trailing space.

Writing uses UTF-8 too, so names like Sofía Martínez arrive intact. If a vendor asks for a different encoding, change it in write_csv(). Python Basics: Files and Exceptions covers reading and writing files in more detail.

Validating Before Anything Leaves the District

validate_students() checks every row and keeps only active students that pass every rule:

  • All required fields are present.
  • The student ID hasn’t appeared earlier in the file.
  • The grade is K or 1 to 12.
  • The email, if there is one, is a district student address, not a personal one.

Rows that fail are reported with their line number, so the person who maintains the SIS can find and fix them. They’re not “fixed” by the script: guessing a missing last name or a grade would put wrong data into the app. Students whose status isn’t active are skipped quietly, since leaving them out is exactly what should happen.

Sending Each App Only What It Needs

"math_app": {
    "schools": {"201"},
    "subjects": {"Math"},
    "student_columns": {
        "sis_id": "student_id",
        "given_name": "first_name",
        ...

Each app’s entry in VENDORS lists the schools and subjects it’s licensed for and the exact columns it gets. build_export() picks that app’s classes, keeps only the students enrolled in them, and copies only the listed columns, renamed to the app’s headers.

That one dictionary is the district’s data minimization rule in code. The SIS export includes birthdate, home_language, and iep, but no app’s student_columns mentions them, so they never leave the district. The reading app doesn’t even get email addresses, because it doesn’t need them. When a vendor asks for another field, the change is one reviewed line, and it should match what your data privacy agreement with that vendor allows (K-12 Data Privacy covers vetting apps and agreements).

Comparing With the Last Sync

compare() reads the students file sent last time and returns three lists of IDs: added (in the new file only), changed (in both, with different values), and removed (in the old file only). Most apps deactivate students who disappear from the roster, so the removed list is the one to watch.

A Safety Check for Broken Exports

if old_rows and len(removed) > len(old_rows) * MAX_REMOVE_SHARE:

If an SIS export is cut off, filtered by mistake, or run before the nightly update finishes, a naive sync would send an empty or half-empty roster, and the app could deactivate hundreds of students overnight. The script refuses to write files when more than 20% of an app’s students would be removed, and keeps the last good files instead. Set MAX_REMOVE_SHARE to fit your district; the end of the school year, when whole grades leave, may need a deliberate manual run.

Logging Every Run

log_sync() appends one line per app to sync_log.csv: when it ran, how many students were sent, how many were added, changed, and removed, and whether the run was stopped. It’s a simple audit trail you can open in Excel when someone asks what was sent and when.

Running the Sync

The first export creates everything. Four rows are skipped with the reason, and each app gets only its own students:

$ python roster_sync.py sis_day1
SIS export: 11 active students, problems found: 4
  SKIPPED line 14: 100013 is missing last_name
  SKIPPED line 15: duplicate student_id 100004
  SKIPPED line 16: 100014 has grade '13'
  SKIPPED line 17: 100015 has a non-district email
reading_app: 6 students, 2 classes (added ['100001', '100002', '100003', '100004', '100005', '100006'], changed none, removed none)
math_app: 5 students, 2 classes (added ['100007', '100008', '100009', '100010', '100011'], changed none, removed none)

The files for the math app use its column names, and contain no birthdates, home languages, or IEP flags:

sis_id,given_name,family_name,grade_level,email
100007,Olivia,Brown,6,[email protected]
100008,Ethan,Davis,6,[email protected]
100009,Isabella,Wilson,7,[email protected]
100010,Lucas,Moore,7,[email protected]
100011,Mia,Taylor,7,[email protected]

A few days later, the SIS staff fixed three of the four problems, Emma Garcia withdrew, Lucas Moore’s last name changed to Moore-Díaz, and Valentina Cruz enrolled in grade 4. The second run sends only those changes:

$ python roster_sync.py sis_day2
SIS export: 13 active students, problems found: 1
  SKIPPED line 15: 100014 has grade '13'
reading_app: 6 students, 2 classes (added ['100016'], changed none, removed ['100003'])
math_app: 7 students, 2 classes (added ['100013', '100015'], changed ['100010'], removed none)

Grade '13' for student 100014 is still waiting for a fix in the SIS, so that student still has no math account. That’s the right result: the report keeps the problem visible until someone corrects the source.

Finally, here’s a broken export that only contains the elementary school’s students, as if the middle school had been left out of the report:

$ python roster_sync.py sis_bad
SIS export: 6 active students, problems found: 0
reading_app: 6 students, 2 classes (added none, changed none, removed none)
math_app: STOPPED, 7 of 7 students would be removed. Check the SIS export; the last files were kept.

The reading app’s files are unchanged, and the math app’s sync is stopped before it could remove all seven students. The log records all three runs:

vendor,students,added,changed,removed,result
reading_app,6,6,0,0,ok
math_app,5,5,0,0,ok
reading_app,6,1,0,1,ok
math_app,7,2,1,0,ok
reading_app,6,0,0,0,ok
math_app,0,0,0,7,stopped

(The real file also has a timestamp column at the start of each line.)

Delivering the Files and Scheduling the Sync

Most vendors that accept CSV rosters give each district an SFTP account and a folder to upload to. Their system picks up the files on a schedule, often nightly. Use the vendor’s documented method, and keep these points in mind:

  • Store SFTP passwords or keys outside the script, such as in the operating system’s credential store or environment variables, never in the code or in a shared folder.
  • Prefer SSH keys to passwords when the vendor supports them.
  • Upload only after the script finishes without a “STOPPED” line for that app.

To run the sync every night, schedule it after the SIS export job. On Windows, use Task Scheduler; on Linux or macOS, a cron entry such as this one runs it at 5:30 a.m. every day:

30 5 * * * cd /srv/roster-sync && /usr/bin/python3 roster_sync.py sis_export

Have someone read the output or the log each morning, at least at first. A script that runs silently is only useful if someone notices when it stops.

Privacy and Security Checklist

Rosters are student records, so the sync process needs the same care as the SIS itself:

  • Check the agreement first. Make sure each app has a signed data privacy agreement before sending it any data, and that its columns match what the agreement allows.
  • Minimize fields. Send only what each app needs; never send the whole SIS export “just in case.”
  • Protect the files. Run the script on a district server or a managed computer, keep the export and output folders readable only by the IT staff who need them, and don’t email roster files.
  • Clean up. Delete old exports on a schedule instead of keeping years of student data in a folder.
  • Offboard apps. When the district stops using an app, stop the feed and ask the vendor to delete the data as the agreement requires.

Laws such as FERPA in the United States, and state student privacy laws, set rules for sharing student records with vendors. Check your district’s policies and legal guidance for the specifics.

Ideas to Extend the Script

  • OneRoster files. Change the column mappings and file names to produce OneRoster CSV files for apps that accept them.
  • Configuration in a file. Move VENDORS into a JSON or CSV file so adding an app doesn’t require editing code.
  • A teachers file. Many apps also want a separate teachers file; build it from teachers.csv the same way.
  • An emailed summary. Send the morning report to the help desk so problems get fixed in the SIS the same day.
  • pandas for larger districts. The csv module is fine for thousands of rows; for bigger exports or more complex joins, pandas may be easier.

Conclusion

Integrating third-party educational apps is an ongoing data management job, not a one-time setup. A short Python script with CSV files can turn it into a repeatable process: validate the SIS data, give each app only the students and fields it’s allowed to have, report what changed, and stop when an export looks wrong. Start with one app, keep the log, and let the reports guide fixes in the SIS, where the data actually lives.