Skip to main content

Module to display dynamic quizzes in Jupyter notebooks and Jupyter Books. Uses JavaScript to provide

Project description

JupyterCards

JupyterCards is a tool for displaying interactive flash cards in Jupyter notebooks and Jupyter Book.

JupyterCards is part of my effort to make open source tools for developing modern, interactive textbooks.

Here is an animated GIF showing JupyterCards in action:

Animated GIF showing the output of JupyterCards for a sample set of 3 cards

Flash card content can be loaded from:

  • a Python list of dict,
  • a JSON local file,
  • via a URL to a JSON file.

As of version 1.7, JupyterCards supports switching cards by swiping left on touch devices.

Note: JupyterCards always requires MathJax to be loaded. If you are using JupyterBook, it may not always load MathJax if you do not have any LaTeX on your page. To resolve this, you can include the invisible math command $\,\!$ in any Markdown cell. I hope to remove this requirement in the future.

Installation

JupyterCards is available via pip:

pip install jupytercards

Keyboard Controls

Verson 2.0.0rc1 adds keyboard controls:

  • Space to flip card over
  • Enter, right arrow, or j to slide to next card

This version is a release candidate, so install like

pip install jupytercards==2.0.0rc1

Notes:

  • In Jupyter Book, you may have to click the card to get focus before using the keyboard shortcuts.
  • In Jupyter Lab, hovering your mouse over the body of the card should be sufficient to send key presses to Jupyter Cards.
  • In both, you may need to avoid math typeset by MathJax because that can intercept key presses.
  • You may disable keyboard control using keyControl keyword parameter: display_flashcards(ref, keyControl = False).
  • If you test the keyboard controls, please add your feedback to the related Issue, or email me/tweet at me.

Notes on JSON File Format

The JSON file should contain a single JSON array of JSON objects. Each JSON object should have two keys that will be utilized:

  • "front": a string containing the text to be shown on the front of the card
  • "back": a string containing the text to be shown on the back of the card

Although using JSON objects for each flashcard is overkill, this model was chosen to support future extensions to this library.

JupyterLite

As of version 2.5.0, JupyterCards should work on JupyterLite after loading the modulue via micropip:

import micropip
await micropip.install('jupytercards')
                       
from jupytercards import display_flashcards
github='https://raw.githubusercontent.com/jmshea/foundations-of-data-science-with-python/main/04-probability1/flashcards/'
display_flashcards(github+'outcomes-samplespaces-events.json')

Making flashcards in Markdown

As of version 1.9.0, I have added helper functions to convert flashcards created in Markdown to the JSON format that JupyterCards expects. In its simplest version, just put the front text in a Markdown heading (line starting with #) and put the back text below. See (Markdown-flashcards.ipynb) for more discussion and examples of how to use this functionality.

Example of generating flashcard files from JupyterBook notebooks

In my Jupyter notebooks that are used as input to JupyterBook, I use panels with the heading "DEFINITION" to call out definitions in the text. I have provided a helper program extractdefinitions.py that I use to scan files for the DEFINITION header and extract the appropriate lines that follow. The resulting terms and definitions are dumped to corresponding JSON files in a "flashcards" directory. An additional JSON file is generated for the whole chapter. extractdefinitions.py takes 2 arguments: the directory to parse and the chapter number to use to label the overall JSON definitions file. This program is very specific to my workflow and I am offering it only as reference in case it can help someone else with a similar situation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupytercards-2.5.6.tar.gz (883.4 kB view details)

Uploaded Source

Built Distribution

jupytercards-2.5.6-py2.py3-none-any.whl (12.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file jupytercards-2.5.6.tar.gz.

File metadata

  • Download URL: jupytercards-2.5.6.tar.gz
  • Upload date:
  • Size: 883.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.29.0

File hashes

Hashes for jupytercards-2.5.6.tar.gz
Algorithm Hash digest
SHA256 9a9670e9f1f3c5d65a90d61bb7c086ad48fd05c17b0edfd72b1bd6bb0b9b216c
MD5 778f7f4c9bd51c1ae50b0393adae6550
BLAKE2b-256 57944c06d498f1e8b34b175baa70f86643d8c3a962088c241fbb789f57c8af21

See more details on using hashes here.

File details

Details for the file jupytercards-2.5.6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for jupytercards-2.5.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 162e4cfcdcb48439c92808d395322c326d3fb94cbf26887ac5d21eb411a84415
MD5 873bb19a40fc3f9b495bb8a1142ee4ed
BLAKE2b-256 d8e265a9fd774f212822c70f82516c6210d793d3baa0a3d531f49efbbef7fd69

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page