A modern web-based quiz and testing system built with Python and aiohttp
Project description
WebQuiz
A modern web-based quiz and testing system built with Python and aiohttp that allows users to take multiple-choice and text input tests with real-time answer validation and performance tracking.
โจ Features
- Multi-Quiz System: Questions loaded from
quizzes/directory with multiple YAML files - Multiple Question Types: Single choice, multiple choice, and text input questions with Python-based validation
- Admin Interface: Web-based admin panel with master key authentication for quiz management
- Registration Approval: Optional admin approval workflow for new registrations with real-time notifications
- Question Randomization: Configurable per-student question order randomization for fair testing
- Question Grouping: Keep related questions together during randomization with
stick_to_the_previousattribute - Dynamic Answer Visibility: Optional delayed answer reveal - show correct answers only after all students complete
- Manual Answer Control: Admin button to reveal answers immediately without waiting for all students
- Dynamic Quiz Switching: Real-time quiz switching with automatic server state reset
- Config File Editor: Web-based configuration editor with Form and YAML views, real-time validation
- Live Statistics: Real-time WebSocket-powered dashboard showing user progress
- Real-time Validation: Server-side answer checking with immediate feedback
- Session Persistence: Cookie-based user sessions for seamless experience
- Performance Tracking: Server-side timing for accurate response measurement
- Data Export: Automatic CSV export with quiz-prefixed filenames and unique suffixes
- AI Integration: Use ChatGPT/Claude for analyzing quiz results and generating questions from existing materials
- Responsive UI: Clean web interface with dark/light theme support
- SSH Tunnel Support: Optional public access via SSH reverse tunnel with auto-reconnect
- Binary Distribution: Standalone PyInstaller executable with auto-configuration
- Comprehensive Testing: 222+ tests covering all functionality with CI/CD pipeline
- Flexible File Paths: Configurable paths for quizzes, logs, CSV, and static files
๐ Quick Start
Prerequisites
- Python 3.9-3.14 (required by aiohttp)
- Poetry (recommended) or pip
- Git
Installation with Poetry (Recommended)
-
Clone the repository
git clone git@github.com:oduvan/webquiz.git cd webquiz
-
Install with Poetry
poetry install -
Run the server
webquiz # Foreground mode webquiz -d # Daemon mode
-
Open your browser
http://localhost:8080
The server will automatically create necessary directories and files on first run.
Alternative Installation with pip
-
Clone and set up virtual environment
git clone git@github.com:oduvan/webquiz.git cd webquiz python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Run the server
python -m webquiz.cli
The server will automatically create necessary directories and files on first run.
๐ Project Structure
webquiz/
โโโ pyproject.toml # Poetry configuration and dependencies
โโโ requirements.txt # Legacy pip dependencies
โโโ .gitignore # Git ignore rules
โโโ CLAUDE.md # Project documentation
โโโ README.md # This file
โโโ webquiz/ # Main package
โ โโโ __init__.py # Package initialization
โ โโโ cli.py # CLI entry point (webquiz command)
โ โโโ server.py # Main application server
โ โโโ build.py # PyInstaller binary build script
โ โโโ binary_entry.py # Binary executable entry point
โ โโโ version_check.py # Version update checking
โ โโโ server_config.yaml.example # Configuration example
โ โโโ templates/ # HTML templates
โ โโโ index.html # Main quiz interface
โ โโโ admin.html # Admin management panel
โ โโโ files.html # File manager interface
โ โโโ live_stats.html # Live statistics dashboard
โ โโโ quiz_selection_required.html # Quiz selection prompt
โ โโโ template_error.html # Error page template
โโโ tests/ # Test suite (14 test files)
โ โโโ conftest.py # Test fixtures and configuration
โ โโโ test_cli_directory_creation.py # CLI and directory tests
โ โโโ test_admin_api.py # Admin API tests
โ โโโ test_admin_quiz_management.py # Quiz management tests
โ โโโ test_config_management.py # Config editor tests
โ โโโ test_registration_approval.py # Registration approval tests
โ โโโ test_registration_fields.py # Registration fields tests
โ โโโ test_index_generation.py # Template generation tests
โ โโโ test_files_management.py # File manager tests
โ โโโ test_integration_multiple_choice.py # Multiple choice integration tests
โ โโโ test_multiple_answers.py # Multiple answer tests
โ โโโ test_show_right_answer.py # Show answer tests
โ โโโ test_selenium_multiple_choice.py # Selenium multiple choice tests
โ โโโ test_selenium_registration_fields.py # Selenium registration tests
โ โโโ test_user_journey_selenium.py # Selenium user journey tests
โโโ .github/
โโโ workflows/
โโโ test.yml # CI/CD pipeline
# Generated at runtime (excluded from git):
โโโ quizzes/ # Quiz files directory
โโโ default.yaml # Default quiz (auto-created)
โโโ *.yaml # Additional quiz files
๐ฅ๏ธ CLI Commands
The webquiz command provides several options:
# Start server in foreground (default)
webquiz
# Start server with admin interface (requires master key)
webquiz --master-key secret123
# Start server with custom directories
webquiz --quizzes-dir my_quizzes
webquiz --logs-dir /var/log
webquiz --csv-dir /data
webquiz --static /var/www/quiz
# Combine multiple options
webquiz --master-key secret123 --quizzes-dir quizzes --logs-dir logs
# Set master key via environment variable
export WEBQUIZ_MASTER_KEY=secret123
webquiz
# Start server as daemon (background)
webquiz -d
webquiz --daemon
# Stop daemon server
webquiz --stop
# Check daemon status
webquiz --status
# Show help
webquiz --help
# Show version
webquiz --version
Key Options
--master-key: Enable admin interface with authentication--quizzes-dir: Directory containing quiz YAML files (default:./quizzes)--logs-dir: Directory for server logs (default: current directory)--csv-dir: Directory for CSV exports (default: current directory)--static: Directory for static files (default:./static)-d, --daemon: Run server in background--stop: Stop daemon server--status: Check daemon status
Daemon Mode Features
- Background execution: Server runs independently in background
- PID file management: Automatic process tracking via
webquiz.pid - Graceful shutdown: Proper cleanup on stop
- Status monitoring: Check if daemon is running
- Log preservation: All output still goes to
server.log
๐ Release Management
This project uses GitHub Actions for automated versioning, PyPI deployment, and GitHub Release creation.
Creating a New Release
- Go to GitHub Actions in the repository
- Select "Release and Deploy to PyPI" workflow
- Click "Run workflow"
- Enter the new version (e.g.,
1.0.6,2.0.0) - Click "Run workflow"
The action will automatically:
- โ
Update version in
pyproject.tomlandwebquiz/__init__.py - โ Run tests to ensure everything works
- โ Commit the version changes
- โ Create a git tag with the version
- โ Build the package using Poetry
- โ Publish to PyPI
- ๐ Create a GitHub Release with built artifacts
What's included in GitHub Releases
Each release automatically includes:
- ๐ฆ Python wheel package (
.whlfile) - ๐ Source distribution (
.tar.gzfile) - ๐ Formatted release notes with installation instructions
- ๐ Links to commit history for detailed changelog
- ๐ Installation commands for the specific version
Prerequisites for Release Deployment
Repository maintainers need to set up:
PYPI_API_TOKENsecret in GitHub repository settings- PyPI account with publish permissions for the
webquizpackage GITHUB_TOKENis automatically provided by GitHub Actions
๐งช Testing
Run the comprehensive test suite:
# With Poetry
poetry run pytest
# Or directly
pytest tests/
# Run with verbose output
pytest tests/ -v
# Run in parallel with 4 workers
pytest tests/ -v -n 4
# Run specific test file
pytest tests/test_admin_api.py
pytest tests/test_registration_approval.py
Test Coverage
The project has 222+ tests across 15 test files covering:
- CLI and Directory Creation (7 tests): Directory and file creation
- Admin API (14 tests): Admin interface and authentication
- Admin Quiz Management (18 tests): Quiz switching and management
- Admin Quiz Editor (7 tests): Wizard mode quiz creation with randomize_questions and show_answers_on_completion
- Config Management (23 tests): Config editor, validation, and form-based JSON updates
- Registration Approval (20 tests): Approval workflow and timing
- Files Management (32 tests): File manager interface
- Index Generation (13 tests): Template generation tests
- Registration Fields (12 tests): Custom registration fields
- Show Right Answer (5 tests): Answer display functionality
- Show Answers on Completion (10 tests): Dynamic answer visibility after all students complete
- Integration Tests (6 tests): Multiple choice, multiple answers
- Selenium Tests (56 tests): End-to-end browser testing
- Auto-Advance (6 tests): Automatic progression behavior
The test suite uses GitHub Actions CI/CD for automated testing on every commit.
๐ฅ Stress Testing
Stress testing has been moved to a separate project for better maintainability and independent versioning.
Installation
# Install from PyPI
pip install webquiz-stress-test
# Or download pre-built binaries from releases
# https://github.com/oduvan/webquiz-stress-test/releases
Quick Start
# Basic test with 10 concurrent users
webquiz-stress-test
# Heavy load test with 100 users
webquiz-stress-test -c 100
# Test custom server
webquiz-stress-test -u http://localhost:9000 -c 50
Features
- Concurrent client simulation with configurable users
- Realistic user behavior (random delays, page reloads)
- Randomized quiz support
- Approval workflow testing
- Detailed performance statistics
- Multi-platform binaries (Linux, macOS, Windows)
Documentation
For complete documentation, see the webquiz-stress-test repository.
๐ Configuration Format
Quiz Files
Questions are stored in YAML files in the quizzes/ directory. The server automatically creates a default.yaml file if the directory is empty.
Example quiz file (quizzes/math_quiz.yaml):
title: "Mathematics Quiz"
randomize_questions: true # Set to true to randomize question order for each student (default: false)
questions:
- question: "What is 2 + 2?"
options:
- "3"
- "4"
- "5"
- "6"
correct_answer: 1 # 0-indexed (option "4")
- question: "What is 5 ร 3?"
options:
- "10"
- "15"
- "20"
- "25"
correct_answer: 1 # 0-indexed (option "15")
Question Randomization:
- Set
randomize_questions: truein your quiz YAML to give each student a unique question order - Each student receives a randomized order that persists across sessions
- Helps prevent cheating and ensures fair testing
- Default is
false(questions appear in YAML order)
Question Grouping (stick_to_the_previous):
- Use
stick_to_the_previous: trueon questions that should stay adjacent to their predecessor during randomization - Useful for reading passages followed by related questions
- Groups are shuffled as units while preserving internal order
- Example: Q1โQ2(sticky)โQ3(sticky) always appear together as [Q1,Q2,Q3]
- First question cannot have this flag (no previous question)
- Admin panel shows ๐ indicator on grouped questions
Question Points:
- Each question can have a custom point value using the
pointsfield (default: 1) - Points are tracked and displayed in:
- Live stats: shows earned points / total points for each user
- Final results: displays points earned along with correct/incorrect count
- Users CSV: includes
earned_pointsandtotal_pointscolumns
- Questions with more than 1 point show a trophy indicator (๐) during the quiz
Example:
questions:
- question: "Easy question"
options:
- "A"
- "B"
- "C"
- "D"
correct_answer: 0
# points: 1 (default, can be omitted)
- question: "Hard question worth 3 points"
options:
- "X"
- "Y"
- "Z"
correct_answer: 2
points: 3 # This question is worth 3 points
Text Input Questions:
In addition to multiple choice questions, you can create text input questions where students type their answer. Questions with checker field are automatically detected as text input questions:
questions:
- question: "What is 2+2?"
default_value: "" # Initial value shown in textarea
correct_value: "4" # Shown when answer is wrong (if show_right_answer is true)
checker: | # Python code to validate the answer
assert user_answer.strip() == '4', 'Expected 4'
points: 1
- question: "Calculate sqrt(16)"
correct_value: "4.0"
checker: |
result = float(user_answer)
assert abs(result - sqrt(16)) < 0.01, f'Expected 4, got {result}'
points: 2
Text Question Fields:
question- Question text (required)checker- Required to identify as text question (can be empty for exact match)default_value- Initial value shown in textarea (optional)correct_value- Correct answer shown when student is wrong (optional)points- Points for correct answer (default: 1)
Checker Code:
- Uses variable
user_answer(the student's text input) - Available:
mathmodule (usemath.sqrt,math.sin, etc.) - Available helper functions:
to_int(str)- Convert string to integer (strips whitespace)distance(str)- Parse distance with units: "2000", "2000m", "2ะบะผ", "2km" all return 2000direction_angle(str)- Parse direction angle: "20" returns 2000, "20-30" returns 2030
- If checker raises any exception, the answer is marked incorrect
- If no checker is provided, exact match with
correct_valueis used (with whitespace stripped)
Checker Templates:
You can configure reusable checker templates in your webquiz.yaml:
checker_templates:
- name: "Exact Match"
code: "assert user_answer.strip() == 'expected', 'Wrong answer'"
- name: "Numeric Check"
code: "assert float(user_answer) == 42, 'Expected 42'"
- name: "Contains Check"
code: "assert 'keyword' in user_answer.lower(), 'Must contain keyword'"
Templates appear in the admin quiz editor for easy insertion.
Server Configuration
Optional server configuration file (webquiz.yaml):
server:
host: "0.0.0.0"
port: 8080
include_ipv6: false # Include IPv6 addresses in network interfaces list
url_format: "http://{IP}:{PORT}/" # URL format for admin panel (use {IP} and {PORT} placeholders)
registration:
approve: false # Set to true to require admin approval
fields:
- name: "full_name"
label: "Full Name"
required: true
quiz:
show_right_answer: false # Show correct answer after submission
show_answers_on_completion: true # Reveal answers only after all students complete
All configuration sections are optional and have sensible defaults.
Answer Visibility Options
WebQuiz offers flexible control over when students can see correct answers:
show_right_answer: true(default): Students see correct answers immediately after submitting each questionshow_right_answer: false: Correct answers are completely hidden during the quiz and on the final results pageshow_answers_on_completion: true: Works withshow_right_answer: falseto reveal answers dynamically:- Answers remain hidden until ALL students complete the quiz
- Students see a waiting message with a reload button
- Once all students finish, correct answers become visible
- If new students register, answers are hidden again until everyone completes
- In approval mode, only approved students count toward completion
Example Use Case: Useful for collaborative learning environments where you want students to discuss answers together after everyone has completed the quiz independently.
SSH Tunnel for Public Access
WebQuiz can expose your local server to the internet via an SSH reverse tunnel, making it accessible from a public URL. This is useful for:
- Running quizzes from a local computer without port forwarding
- Temporary public access without dedicated hosting
- Classroom environments where students connect from outside the network
Configuration (webquiz.yaml):
Option 1: Fetch config from server
tunnel:
server: "tunnel.example.com" # SSH tunnel server hostname
public_key: "keys/id_ed25519.pub" # Path to SSH public key (auto-generated if missing)
private_key: "keys/id_ed25519" # Path to SSH private key (auto-generated if missing)
# Config will be fetched from https://tunnel.example.com/tunnel_config.yaml
Option 2: Local config (bypasses server fetch)
tunnel:
server: "tunnel.example.com"
public_key: "keys/id_ed25519.pub"
private_key: "keys/id_ed25519"
socket_name: "my-quiz-socket" # Optional: Fixed socket name (default: random 6-8 chars)
config: # Optional: Provide locally to skip fetching from server
username: "tunneluser"
socket_directory: "/var/run/tunnels"
base_url: "https://tunnel.example.com/tests"
How it works:
- Automatic Key Generation: If keys don't exist, WebQuiz automatically generates ED25519 SSH key pairs
- Admin Control: Navigate to the admin panel to see the tunnel status
- Copy Public Key: Copy the generated public key and add it to
~/.ssh/authorized_keyson your tunnel server - Connect: Click the "Connect" button in the admin panel to establish the tunnel
- Public URL: Once connected, a public URL will be displayed (e.g.,
https://tunnel.example.com/tests/a3f7b2/) - Auto-Reconnect: If the connection drops, WebQuiz automatically attempts to reconnect
Server Requirements:
- The tunnel server must be configured to support Unix domain socket forwarding
- The server should provide a
tunnel_config.yamlendpoint athttps://[server]/tunnel_config.yamlwith:username: tunneluser socket_directory: /var/run/tunnels base_url: https://tunnel.example.com/tests
Security Notes:
- SSH keys are generated with no passphrase for automated connection
- Keys are stored with proper permissions (600 for private key)
- Connection is admin-initiated (no auto-connect on startup)
- Connection status is shown in real-time via WebSocket
๐ Data Export
User responses are automatically exported to CSV files with quiz-prefixed filenames and unique suffixes to prevent overwrites:
Example: math_quiz_user_responses_0001.csv
user_id,question,selected_answer,correct_answer,is_correct,time_taken_seconds
123456,"What is 2 + 2?","4","4",True,3.45
123456,"What is 5 ร 3?","15","15",True,2.87
A second file with .users.csv suffix contains user statistics:
user_id,username,registered_at,total_questions_asked,correct_answers,earned_points,total_points,total_time
123456,student1,2025-01-15T10:30:00,5,4,7,9,12:46
total_time- Total quiz completion time inMM:SSformat (minutes:seconds)earned_points- Points earned from correct answerstotal_points- Maximum possible points for questions answered
CSV files are created with proper escaping and include all user response data. Files are flushed periodically (every 5 seconds) to ensure data persistence.
๐จ Customization
Adding Your Own Quizzes
-
Create a YAML file in the
quizzes/directory# Example: quizzes/science_quiz.yaml -
Add your questions following the format:
title: "Science Quiz" questions: - question: "What is H2O?" options: - "Water" - "Hydrogen" - "Oxygen" - "Salt" correct_answer: 0
-
Switch to your quiz via the admin interface
- Access
/adminwith your master key - Select your quiz from the dropdown
- Click "Switch Quiz"
- Access
Admin Interface
Enable admin features with a master key:
webquiz --master-key secret123
Access admin panels:
/admin- Quiz management and user approval/files- View logs, CSV files, and edit configuration/live-stats- Real-time user progress dashboard
The admin panel automatically detects when the package has been updated while the server is running and displays a "Restart Required" notification, prompting you to restart the server to use the new version.
Styling
- Templates are located in
webquiz/templates/ - Built-in dark/light theme toggle
- Responsive design works on mobile and desktop
- Generated
static/index.htmlcan be customized (regenerates on quiz switch)
๐ ๏ธ Development
Building Binary Executable
Create a standalone executable with PyInstaller:
# Build binary
poetry run build_binary
# Or directly
python -m webquiz.build
# The binary will be created at:
./dist/webquiz
# Run the binary
./dist/webquiz
./dist/webquiz --master-key secret123
The binary includes all templates and configuration examples, with automatic directory creation on first run.
Key Technical Decisions
- Multi-quiz system: Questions loaded from
quizzes/directory with YAML files - Master key authentication: Admin endpoints protected with decorator-based authentication
- Server-side timing: All timing calculated server-side for accuracy
- Server-side question randomization: Random question order generated server-side, stored per-user, ensures unique randomized order for each student with session persistence
- Middleware error handling: Clean error management with proper HTTP status codes
- CSV module usage: Proper escaping for data with commas/quotes
- Smart file naming: CSV files prefixed with quiz names, unique suffixes prevent overwrites
- Dynamic quiz switching: Complete server state reset when switching quizzes
- WebSocket support: Real-time updates for admin and live statistics
- Binary distribution: PyInstaller for standalone executable with auto-configuration
Architecture
- Backend: Python 3.9-3.14 with aiohttp async web framework
- Frontend: Vanilla HTML/CSS/JavaScript (no frameworks)
- Storage: In-memory with periodic CSV backups (30-second intervals)
- Session Management: Cookie-based with server-side validation
- Real-time Features: WebSocket for live stats and admin notifications
๐ Troubleshooting
Common Issues
Port already in use:
# Kill process using port 8080
lsof -ti:8080 | xargs kill -9
Virtual environment issues:
# Recreate virtual environment
rm -rf venv
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Quiz not loading:
- Check that quiz YAML files have valid syntax
- Verify
quizzes/directory exists and contains.yamlfiles - Check server logs for errors
- Restart server after adding new quiz files
Admin interface not accessible:
- Ensure you started server with
--master-keyoption - Or set
WEBQUIZ_MASTER_KEYenvironment variable - Check that you're using the correct master key
Tests failing:
- Always run tests in virtual environment:
source venv/bin/activate - Install test dependencies:
poetry installorpip install -r requirements.txt - Use parallel testing:
pytest tests/ -v -n 4
Daemon not stopping:
# Check status
webquiz --status
# Force kill if needed
cat webquiz.pid | xargs kill -9
rm webquiz.pid
๐ License
This project is open source. Feel free to use and modify as needed.
๐ค Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
๐ Support
For questions or issues:
- Check the server logs (
server.log) - Run the test suite to verify setup
- Review this README and
CLAUDE.mdfor detailed documentation
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 webquiz-1.13.1.tar.gz.
File metadata
- Download URL: webquiz-1.13.1.tar.gz
- Upload date:
- Size: 123.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
687f16e2b39e3b99424191dd44f655f66cb547c8b48f754342ab77401202814f
|
|
| MD5 |
521f76527d4bd3a843ac650f182a2b42
|
|
| BLAKE2b-256 |
b7aed976c8ebd7bfd18eecdfaacc25e5ee49a3310ce4f59803deff0898d0cc17
|
File details
Details for the file webquiz-1.13.1-py3-none-any.whl.
File metadata
- Download URL: webquiz-1.13.1-py3-none-any.whl
- Upload date:
- Size: 120.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43aafa66e72291c89d76be9dbf4caa0dd54ce92fe9bdcf1aaec63a97e5f2d530
|
|
| MD5 |
4f878898f2c0fe487c29c69ebb1d2b8b
|
|
| BLAKE2b-256 |
bbac0b458d67a84cbc2ef1723314bce96a41ef22cdb545524d11e9d76034d475
|