Exam Kernel
A wrapper for the IPython kernel that sanitizes the input before execution.
A more in depth explanation can be found in the docs.
This kernel blocks all magic commands including !.
The libraries a user can use can be restricted by blocking or allowing certain imports. The module importlib is blocked by default.
Installation
pip install exam_kernel
python -m exam_kernel.install --sys-prefix
Configuration
You can configure the kernel via the ipython_config.py.
This file is usually located under ~/.ipython.
1. Initialization Code
This is the code that will be executed every time the kernel is initialized and set via the configuration option IPKernelApp.exec_lines.
Example config:
# sample ipython_config.py
c = get_config()
c.IPKernelApp.exec_lines = ['import math', 'import random']
In this example the libraries math and random are imported every time the kernel is initialized, making them available to the user right away.
2. Allowed Imports
If you want to allow the user to only use certain libraries, you can specify them using the allowed_imports configuration option. All other libraries will be blocked by default if this option is set.
Example config:
# sample ipython_config.py
c = get_config()
c.ExamKernel.allowed_imports = ['math', 'numpy', 'scipy']
In this example the student can only import the libraries math, numpy and scipy. If the user tries to import any other library (e.g. matplotlib), he or she will see the following message:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-041c468338fc> in <module>
----> 1 raise ModuleNotFoundError('No module named matplotlib or matplotlib blocked by kernel.')
ModuleNotFoundError: No module named matplotlib or matplotlib blocked by kernel.
3. Blocked Imports
If you want to block the user from importing certain libraries, but let them use all others, you can use the blocked_imports configuration option.
If the allowed_import option is used, the blocked imports will take no effect.
Example config:
# sample ipython_config.py
c = get_config()
c.ExamKernel.blocked_imports = ['math', 'numpy', 'scipy']
In this example the student can not import the libraries math, numpy and scipy. If the user tries to import a blocked library (e.g. math), he or she will see the following message:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-041c468338fc> in <module>
----> 1 raise ModuleNotFoundError('No module named math or math blocked by kernel.')
ModuleNotFoundError: No module named math or math blocked by kernel.
Metadata
Release files for exam-kernel 0.2.0
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 |
|---|---|---|---|---|
| exam_kernel-0.2.0.tar.gz | 9.1 kB | Without provenance | Details for exam_kernel-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| exam_kernel-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for exam_kernel-0.2.0-py3-none-any.whl |
Total release size: 15.8 kB
Release files / exam_kernel-0.2.0.tar.gz
| Download URL | exam_kernel-0.2.0.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
22f9883a38e6caa3da0236154db804eda4f6c3e350132a57348e0728b8b5c32f
|
|
BLAKE2b-256 checksum How to use checksums |
9c894bac24a3ef1417dea51b84b78eac36a7400f32e701d0b6548728d8b0dc99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / exam_kernel-0.2.0-py3-none-any.whl
| Download URL | exam_kernel-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
beaba680d9c9f6fb18cf220665d7b72ed19dded13b09187096a3bdf5ba27b81d
|
|
BLAKE2b-256 checksum How to use checksums |
1b3b9286093f6ad42a0d090386d9bc8ac6edff0887149b534a1eb7bf45fd15d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for exam-kernel 0.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.