ub-grader
Python library for students to self-grade assignments locally and generate reports to submit to instructors.
Table of Contents
- Quick Installation
- Student Usage
- Spec Format
- Troubleshooting
- License
1. Quick Installation
pip install ub-grader
Requires Python 3.10+.
2. Student Usage
Basic Usage
from ub_grader import init_students, load_spec, grade
from solution import solve # your target function
# Register students (single student or multiple for group work)
init_students([
{"niub": "A123", "first_name": "Alice", "last_name": "Doe"},
])
# Load assignment specification
load_spec("https://server/assignments/p1.json") # or file:///abs/path/p1.json
# Grade your solution
result = grade(
solve,
student_id="A123",
)
print("Final score:", result["final_score"], "/", result["max_score"])
After running, a report file will be generated. Submit this file to your instructor.
Step-by-Step Guide
- Install the library:
pip install ub-grader - Create your solution: Write your solution function in a Python file
- Register: Use
init_students()with your student ID and name (supports single or multiple students) - Load spec: Use
load_spec()with the assignment specification URL provided by your instructor - Grade: Use
grade()with your solution function - Submit: Send the generated report file to your instructor
Multiple Students (Group Work)
You can register multiple students at once, which is useful for group assignments or when managing multiple student accounts:
init_students([
{"niub": "A123", "first_name": "Alice", "last_name": "Doe"},
{"niub": "B456", "first_name": "Bob", "last_name": "Smith"},
{"niub": "C789", "first_name": "Charlie", "last_name": "Brown"},
])
# Each student can then generate their own report
result_alice = grade(solve, student_id="A123")
result_bob = grade(solve, student_id="B456")
3. Spec Format
Assignment specifications are provided by your instructor as JSON files. A typical spec includes:
{
"version": "1.0.0",
"assignment_id": "p1",
"tests": [
{
"id": "t1",
"input": { "args": [1, 2], "kwargs": {} },
"expected": 3,
"weight": 1,
"expected_hidden": false,
"time_limit_ms": 500,
"memory_limit_kb": 10000,
"comparison": "equal"
}
],
"scoring": {
"mode": "weighted_sum_with_penalties",
"rounding": 2,
"penalties": {},
"max_score": 10
}
}
Key points for students:
- Tests may have
expected_hidden: true, which means you won't see the expected output, only pass/fail - Each test has time and memory limits
- Exceeding limits may result in penalties applied to your score
4. Troubleshooting
Common Issues
| Issue | Likely Cause | Solution |
|---|---|---|
RuntimeError: No spec loaded |
Forgot to call load_spec() |
Call load_spec() before grade() |
ValueError: Missing required field |
Malformed spec JSON | Contact your instructor for a valid spec |
| Very low score | Tests failing or penalties applied | Review your logic and check time/memory limits |
Best Practices
- Use a dedicated virtual environment:
python -m venv myenv && source myenv/bin/activate - Don't modify the assignment spec file
- Test your solution thoroughly before final grading
- Keep backups of your solution code
Getting Help
- Check that your Python version is 3.10 or higher
- Ensure you have the latest version:
pip install -U ub-grader - Review the error messages carefully - they usually indicate the specific issue
- Contact your instructor if you suspect issues with the assignment specification
5. License
MIT
Metadata
Release files for ub-grader 0.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ub_grader-0.3.5.tar.gz | 17.4 kB | With provenance | Details for ub_grader-0.3.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ub_grader-0.3.5-py3-none-any.whl | Python 3 | none | any | Details for ub_grader-0.3.5-py3-none-any.whl |
Total release size: 37.0 kB
Release files / ub_grader-0.3.5.tar.gz
| Download URL | ub_grader-0.3.5.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
64414f6a304780fb5a790a4fd9cd2a1b1adf244f0d9df1ec75d3dd23ecabba2f
|
|
BLAKE2b-256 checksum How to use checksums |
8d6c96f3e08d7661cb5ab859fffb29d3eff53b5982e5c5488bc8054c03b3eb4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 2, 2025.
Transparency logRelease files / ub_grader-0.3.5-py3-none-any.whl
| Download URL | ub_grader-0.3.5-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
87bd24562f1f2d0a79e3d1679864d6a409adeb07f363cac9afc09d292a068780
|
|
BLAKE2b-256 checksum How to use checksums |
f48ec125aada1fd78c43019fdeb48bfb007f2599a07042bacc9362c68e440afe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 2, 2025.
Transparency logSecurity for ub-grader 0.3.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for ub_grader-0.3.5.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 2, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.