AS
ALOC Stationdeveloper docs
DOCS/DEVELOPER PORTAL
v1.0.0
folio 4.3 — cookbook

Automate School Exam Paper Generation in Python

Learn how to write a zero-dependency Python script using standard libraries to assemble syllabus-balanced examination papers, generate answer keys, and export structured JSON test suites.

View Python Repo on GitHub8 min implementation

4.3.0Zero-Dependency Architecture

This automation script uses only Python's built-in urllib.request, json, and argparse modules. No pip install or virtual environments are required.

4.3.1Step 1: Python Assessment Generator Script

Create a file named generate_paper.py:

#!/usr/bin/env python3
import json
import os
import urllib.request
import urllib.parse

API_KEY = os.getenv("ALOC_API_KEY", "alc_live_your_key_here")
BASE_URL = os.getenv("ALOC_BASE_URL", "https://dev.aloc.com.ng/api/v1")

def assemble_assessment(subject="mathematics", exam_type="jamb", preset="jamb_standard_40"):
    url = f"{BASE_URL}/assessments/generate"
    payload = json.dumps({
        "subject": subject,
        "examType": exam_type,
        "preset": preset,
        "shuffleOptions": True,
        "seed": f"school_mock_{subject}"
    }).encode("utf-8")

    req = urllib.request.Request(
        url,
        data=payload,
        headers={
            "X-API-Key": API_KEY,
            "Content-Type": "application/json",
            "Accept": "application/json"
        },
        method="POST"
    )

    with urllib.request.urlopen(req) as response:
        return json.loads(response.read().decode("utf-8"))

if __name__ == "__main__":
    paper = assemble_assessment(subject="physics", exam_type="waec")
    print(f"✅ Generated {len(paper['data']['questions'])} calibrated questions")
    
    with open("exam_paper.json", "w") as f:
        json.dump(paper, f, indent=2)
    print("💾 Saved to exam_paper.json")

4.3.2Step 2: Execute Script

Run the generator with your environment variable:

ALOC_API_KEY="alc_live_..." python3 generate_paper.py
Explore the Interactive API Playground

Test assessment generation and option shuffling directly in your browser.

Open API Playground