Skip to main content

py2gift

py2gift is a library meant to write question banks in GIFT format (Moodle) programmatically in Python. Ultimately, questions can be written (though this is not a requirement) from a Jupyter notebook. The advantages are:

  • you can use all your Python skills to compute whatever is required for the statement, solution and feedback of a question
  • it makes easy to write different (random) versions of the same question
  • questions can be previewed (pictures, $\LaTeX$…) in the notebook
  • no need to install anything: you can click this mybinder badge, Binder , open any of the provided examples, and start writing your questions right now from the browser (the file generated at the end of the notebook, accesible through a link, can be imported in Moodle).

This library relies on gift-wrapper and it has been created using nbdev. The latter fact means you can explore the actual source code through jupyter notebooks and see the inner workings of each individual piece.

Setup

Since the library is in PyPI

pip install py2gift

should do.

Manual

If you’d rather clone this repository, the command below should install all the required packages

pip install pandas numpy matplotlib ruamel.yaml gift-wrapper

How to use it

Writing a question involves specifying the statement and, optionally, the feedback in different notebook cells. In any case, variables, specified with the prefix !, can be included, and those are meant to be filled in from within a Python class. This comes very handy when you want to create different versions of a single question in which some input data (maybe in the form of a picture) randomly changes from question to question. Then, you can instruct py2gift to call your Python code a number of times, each one giving rise to a different version of the same question (as long as some variable is set at random, e.g., by exploiting the functionality in np.random). The solution, whose format depends on the question type, must also be set from within the code.

Underneath, images are handled by gift-wrapper, and hence paths (e.g., images/scheme.svg) to either .tex (that can be compiled with pdflatex) or .svg files can be included in the statement, solution or feedback of a question. Moreover, they can be included through one of the variables (prefix !), and hence random (but nonetheless meaningful) pictures are a possibility.

Notice that the difference between two instances of the same question can be minor or significant. Ultimately, it depends on how sophisticated your Python code is (if the latter can solve the question/problem in a very general form, and you are also able to present it in the statement, then it is fine).

Besides the above mentioned core functionality, py2gift provides some extra functions to ease the process of writing questions (modules tex, util, time, hash). However, a thorough description of the functionality would be very dry and you are probably better off by taking a look at one of the sample notebooks (minimal or example_1). Also, you can take a look at the documentation.

Metadata

Release files for py2gift 0.0.6.2

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

Source distribution (sdist)

Source distribution for py2gift 0.0.6.2
File Size Uploaded Provenance
py2gift-0.0.6.2.tar.gz 29.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for py2gift 0.0.6.2
File Interpreter ABI Platform
py2gift-0.0.6.2-py3-none-any.whl Python 3 none any Details

Total release size: 59.7 kB

Release files / py2gift-0.0.6.2.tar.gz

Download URL py2gift-0.0.6.2.tar.gz
Size 29.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d2f2f45a3462aa723d506713e82d37be9a9a5f853db6ceb1e27f9d2b1b2a8b82
BLAKE2b-256 checksum
How to use checksums
2bd3e7be8a06e48e4fd68626211f155e60f3ed298d81027a5f0973d24c5dca05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Release files / py2gift-0.0.6.2-py3-none-any.whl

Download URL py2gift-0.0.6.2-py3-none-any.whl
Size 30.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4bff63b73dffe54630418a03498a544a87beea629c43b7f1cf610faa142d778f
BLAKE2b-256 checksum
How to use checksums
43e7c2f4245473af44af9e63b1ba38be5393cd7120b290db18f1f502fbeccc5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Security for py2gift 0.0.6.2

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.

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