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.
This automation script uses only Python's built-in urllib.request, json, and argparse modules. No pip install or virtual environments are required.
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")Run the generator with your environment variable:
ALOC_API_KEY="alc_live_..." python3 generate_paper.pyTest assessment generation and option shuffling directly in your browser.