Skip to main content

Correction Helper

Project

This is just a set of tools to help writing correction bots in Python for Python.

It is used for hackinscience, but could be used elsewhere.

Security considerations

Running student code is probably really unsafe, unless you trust your students not to drop you a backdoor.

This projet does not help with security in any ways, maybe take a look at firejail if you have trust issues (Yes you can use correction-helper inside firejail).

Usage

To install it, run: pip install correction-helper.

In your checking code, you can use it like this:

The student_code decorator

This decorator is aimed to catch most problems that could happen in student code, use it simply as:

with student_code():
    their_function()

Find a more complete example in the examples/ directory.

Allowed parameters for student_code, and their default values

print_prefix="Your code printed:"

Message to display before the student prints (in case print_allowed is False or None).

It's allowed to give a list of strings, in which case they'll be separated by "\n\n", useful to render markdown paragraphs.

too_slow_message="Your program looks too slow, looks like an infinite loop."

Message to display in case the code runs slower than the given timeout (defaults to 1s).

It's allowed to give a list of strings, in which case they'll be separated by "\n\n", useful to render markdown paragraphs.

prefix=()

A prefix for print_prefix, exception_prefix, and too_slow_message=, usefull to deduplicate strings, like:

with student_code(
    prefix="While calling blahblah('bar')",
    print_prefix="it printed:",
    exception_prefix="it raised:",
    too_slow_message="it took more than 1s, had to kill it.",
):
    blahblah('bar')

friendly=False

To use, or not friendly-traceback instead of bare Python exceptions.

print_allowed=True

To allow or deny the student to print to stdout and stderr.

  • True: Prints are allowed (and displayed).
  • None: Prints are allowed (but not displayed).
  • False: Prints are disallowed (and displayed).

In all cases you can read what they printed using the value of the context manager:

with student_code(print_allowed=None) as run:
    their_function()
assert run.err == ""
assert run.out == "42"

Good practices

Write the student checking code a you would write unit test for your own code.

Metadata

Release files for correction-helper 2026.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for correction-helper 2026.3
File Size Uploaded
correction_helper-2026.3.tar.gz 12.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for correction-helper 2026.3
File Interpreter ABI Platform
correction_helper-2026.3-py3-none-any.whl Python 3 none any Details

Total release size: 22.3 kB

Release files / correction_helper-2026.3.tar.gz

Download URL correction_helper-2026.3.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8aaa369b4ed65b98e7ca90b3ce83c370a434383c600532cfdcaa869d4f29dade
BLAKE2b-256 checksum
How to use checksums
f3d92e051327bf48c2e0d918dfd6691cc5c5cbd2d41dca9a4bfa011f1e7d435f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / correction_helper-2026.3-py3-none-any.whl

Download URL correction_helper-2026.3-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03340f2397b18caa72dcfa02c7e0f6993d3d52a692aa213f30e6c2410fe6b10e
BLAKE2b-256 checksum
How to use checksums
00e55c184a6cd84768565478cb046ecbd9f7df79ab0812b7e016f6e2d10400ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

2026.3 This release

2 release files

2026.2

2 release files

2025.9

2 release files

2025.3

2 release files

2024.1

2 release files

2023.6

2 release files

2023.5

2 release files

2022.2

2 release files

2021.6

2 release files

2021.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page