Generate randomized quiz questions for Canvas LMS and PDF exams
Project description
QuizGenerator
Generate randomized quiz questions for Canvas LMS and PDF exams with support for multiple question types, automatic variation generation, and QR code-based answer keys.
Features
- Multiple Output Formats: Generate PDFs (LaTeX or Typst) and Canvas LMS quizzes
- Automatic Variations: Create unique versions for each student
- Extensible: Plugin system for custom question types
- Built-in Question Library: Memory management, process scheduling, calculus, linear algebra, and more
- QR Code Answer Keys: Regenerate exact exam versions from QR codes
- Canvas Integration: Direct upload to Canvas with variation support
Installation
pip install QuizGenerator
Reproducible installs (recommended)
If you want a fully pinned environment for a semester, use the lockfile:
uv sync --locked
System Requirements
- Python 3.12+
- Typst (default PDF renderer)
- Optional: LaTeX distribution with
latexmk(if using--latex) - Recommended: Pandoc (for markdown conversion)
Optional Dependencies
# For QR code grading support
pip install "QuizGenerator[grading]"
# For CST463 machine learning questions
pip install "QuizGenerator[cst463]"
Quick Start
Need a 2‑minute setup? See documentation/quickstart.md.
1. Create a quiz configuration (YAML)
# my_quiz.yaml
name: "Midterm Exam"
questions:
10: # 10-point questions
"Process Scheduling":
class: FIFOScheduling
5: # 5-point questions
"Memory Paging":
class: PagingQuestion
"Vector Math":
class: VectorAddition
2. Generate PDFs
quizgen --yaml my_quiz.yaml --num_pdfs 3
PDFs will be created in the out/ directory.
3. Upload to Canvas
# Set up Canvas credentials in ~/.env first:
# CANVAS_API_URL=https://canvas.instructure.com
# CANVAS_API_KEY=your_api_key_here
quizgen \
--yaml my_quiz.yaml \
--num_canvas 5 \
--course_id 12345
Creating Custom Questions
QuizGenerator supports two approaches for adding custom question types:
Option 1: Entry Points (Recommended for Distribution)
Create a pip-installable package:
# pyproject.toml
[project.entry-points."quizgenerator.questions"]
my_question = "my_package.questions:MyCustomQuestion"
After pip install, your questions are automatically available!
Option 2: Direct Import (Quick & Easy)
Add to your quiz YAML:
custom_modules:
- my_questions # Import my_questions.py
questions:
10:
"My Question":
class: MyCustomQuestion
See documentation/custom_questions.md for complete guide.
Question Authoring Pattern (New)
All questions follow the same three‑method flow:
class MyQuestion(Question):
@classmethod
def _build_context(cls, *, rng_seed=None, **kwargs):
context = super()._build_context(rng_seed=rng_seed, **kwargs)
rng = context.rng
context["value"] = rng.randint(1, 10)
return context
@classmethod
def _build_body(cls, context):
body = ca.Section()
body.add_element(ca.Paragraph([f"Value: {context['value']}"]))
body.add_element(ca.AnswerTypes.Int(context["value"], label="Value"))
return body
@classmethod
def _build_explanation(cls, context):
explanation = ca.Section()
explanation.add_element(ca.Paragraph([f"Answer: {context['value']}"]))
return explanation
Notes:
- Always use
context.rng(orcontext["rng"]) for deterministic randomness. - Avoid
refresh(); it is no longer part of the API.
Built-in Question Types
Operating Systems (CST334)
FIFOScheduling,SJFScheduling,RoundRobinSchedulingPagingQuestion,TLBQuestionSemaphoreQuestion,MutexQuestion
Machine Learning / Math (CST463)
VectorAddition,VectorDotProduct,VectorMagnitudeMatrixAddition,MatrixMultiplication,MatrixTransposeDerivativeBasic,DerivativeChainGradientDescentStep
General
FromText- Custom text questionsFromGenerator- Programmatically generated questions (requires--allow_generatororQUIZGEN_ALLOW_GENERATOR=1)
Documentation
Canvas Setup
- Create a
~/.envfile with your Canvas credentials:
# For testing/development
CANVAS_API_URL=https://canvas.test.instructure.com
CANVAS_API_KEY=your_test_api_key
# For production
CANVAS_API_URL_prod=https://canvas.instructure.com
CANVAS_API_KEY_prod=your_prod_api_key
- Use
--prodflag for production Canvas instance:
quizgen --prod --num_canvas 5 --course_id 12345
Advanced Features
Typst Support
Typst is the default for faster compilation. Use --latex to force LaTeX:
quizgen --latex --num_pdfs 3
Experimental: --typst_measurement uses Typst to measure question height for tighter layout.
It can change pagination and ordering, so use with care on finalized exams.
Deterministic Generation
Use seeds for reproducible quizzes:
quizgen --seed 42 --num_pdfs 3
QR Code Regeneration
Each generated exam includes a QR code that stores:
- Question types and parameters
- Random seed
- Version information
Use the grading tools to scan QR codes and regenerate exact exam versions.
Project Structure
QuizGenerator/
├── QuizGenerator/ # Main package
│ ├── question.py # Question base classes and registry
│ ├── quiz.py # Quiz generation logic
│ ├── contentast.py # Content AST for cross-format rendering
│ ├── premade_questions/ # Built-in question library
│ └── canvas/ # Canvas LMS integration
├── example_files/ # Example quiz configurations
├── documentation/ # User guides
└── quizgen # CLI entry point
Contributing
Contributions welcome! Areas of interest:
- New question types
- Additional LMS integrations
- Documentation improvements
- Bug fixes
License
GNU General Public License v3.0 or later (GPLv3+) - see LICENSE file for details
Citation
If you use QuizGenerator in academic work, please cite:
@software{quizgenerator,
author = {Ogden, Sam},
title = {QuizGenerator: Automated Quiz Generation for Education},
year = {2024},
url = {https://github.com/OtterDen-Lab/QuizGenerator}
}
Support
- Issues: https://github.com/OtterDen-Lab/QuizGenerator/issues
- Documentation: https://github.com/OtterDen-Lab/QuizGenerator/tree/main/documentation
Note: This tool is designed for educational use. Ensure compliance with your institution's academic integrity policies when using automated quiz generation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quizgenerator-0.12.0.tar.gz.
File metadata
- Download URL: quizgenerator-0.12.0.tar.gz
- Upload date:
- Size: 267.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e70ced82cbfeefc2db1430dc23ebcc911d147bf87373123ebb6e7d95d504272
|
|
| MD5 |
10663ff460b0092bdb5c1f86d4a06003
|
|
| BLAKE2b-256 |
ae67a9c56c383a4416b469353a57d779bebd0656e9191c1d8e18d79046863d3f
|
File details
Details for the file quizgenerator-0.12.0-py3-none-any.whl.
File metadata
- Download URL: quizgenerator-0.12.0-py3-none-any.whl
- Upload date:
- Size: 182.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6433d2e4543acf35c5374214d05c546d4ec914bfe177c5417f4e55a8204abf59
|
|
| MD5 |
efa36cef87f0989d482b074e503660bd
|
|
| BLAKE2b-256 |
5ab807dd84c456136eeaca851b94a7d948219be5c9f997b900da2f76bf176ed1
|