Skip to content

mcqpy.question.question_bank

Definition of the QuestionBank class for managing multiple-choice questions.

Classes:

  • QuestionBank

    A collection of multiple-choice questions with filtering and retrieval capabilities.

QuestionBank

QuestionBank(
    items: list[BankItem], seed: int | None = None
)

A collection of multiple-choice questions with filtering and retrieval capabilities.

Methods:

add_filter

add_filter(filter: BaseFilter)

Add a filter to the question bank.

Parameters:

  • filter

    (BaseFilter) –

    An instance of BaseFilter to apply when retrieving questions

from_directories classmethod

from_directories(
    directories: list[str], glob_pattern="*.yaml", **kwargs
)

Create a QuestionBank by loading questions from specified directories. Ensures no duplicate slugs are present.

Parameters:

  • directories

    (list[str]) –

    List of directory paths to load questions from

  • glob_pattern

    Glob pattern to match question files (default: '*.yaml')

from_questions classmethod

from_questions(questions: list[Question], **kwargs)

Create a QuestionBank from a list of Question objects.

Parameters:

  • questions

    (list[Question]) –

    List of Question instances to include in the bank

get_all_questions

get_all_questions() -> list[Question]

Retrieve all questions in the bank.

get_all_tags

get_all_tags() -> dict[str, int]

Retrieve all tags in the question bank along with their counts.

get_by_qid

get_by_qid(qid: str) -> Question

Retrieve a question by its QID.

Parameters:

  • qid

    (str) –

    The QID identifier of the question

get_by_slug

get_by_slug(slug: str) -> Question

Retrieve a question by its slug.

Parameters:

  • slug

    (str) –

    The slug identifier of the question

get_filtered_questions

get_filtered_questions(
    number_of_questions: int | None = None,
    shuffle: bool = False,
    sorting: Literal["none", "slug"] = "none",
) -> list[Question]

Retrieve questions after applying all added filters.

Parameters:

  • number_of_questions

    (int | None, default: None ) –

    Maximum number of questions to return (None for all)

  • shuffle

    (bool, default: False ) –

    If True, shuffle the questions before returning

  • sorting

    (Literal['none', 'slug'], default: 'none' ) –

    Sorting method: 'none' for no sorting, 'slug' to sort by slug