qbreader package¶
Submodules¶
- qbreader.asynchronous module
- qbreader.synchronous module
- qbreader.types module
TossupBonusPacketQueryResponseAnswerJudgementCategorySubcategorySubcategory.LITERATURESubcategory.HISTORYSubcategory.SCIENCESubcategory.FINE_ARTSSubcategory.RELIGIONSubcategory.MYTHOLOGYSubcategory.PHILOSOPHYSubcategory.SOCIAL_SCIENCESubcategory.CURRENT_EVENTSSubcategory.GEOGRAPHYSubcategory.OTHER_ACADEMICSubcategory.TRASHSubcategory.AMERICAN_LITERATURESubcategory.BRITISH_LITERATURESubcategory.CLASSICAL_LITERATURESubcategory.EUROPEAN_LITERATURESubcategory.WORLD_LITERATURESubcategory.OTHER_LITERATURESubcategory.AMERICAN_HISTORYSubcategory.ANCIENT_HISTORYSubcategory.EUROPEAN_HISTORYSubcategory.WORLD_HISTORYSubcategory.OTHER_HISTORYSubcategory.BIOLOGYSubcategory.CHEMISTRYSubcategory.PHYSICSSubcategory.OTHER_SCIENCESubcategory.VISUAL_FINE_ARTSSubcategory.AUDITORY_FINE_ARTSSubcategory.OTHER_FINE_ARTS
DifficultyDirectiveQuestionTypeSearchTypeValidDifficultiesUnnormalizedDifficultyUnnormalizedCategoryUnnormalizedSubcategory
Module contents¶
The official qbreader API python wrapper.
Note
Even though useful type aliases defined in qbreader.types are reexported here,
they are not documented here by sphinx-autodoc, but are documented in the
types module.
- class qbreader.Async¶
Bases:
objectThe asynchronous qbreader API wrapper.
- session: ClientSession¶
- async classmethod create(session: ClientSession | None = None) Self¶
Create a new Async instance.
__init__()is not async, so this is necessary.- Parameters:
session (aiohttp.ClientSession, optional) – The aiohttp session to use for requests. If none is provided, a new session will be created.
- Returns:
The new Async instance.
- Return type:
- async query(questionType: qbreader.types.QuestionType = 'all', searchType: qbreader.types.SearchType = 'all', queryString: str | None = '', exactPhrase: bool | None = False, ignoreDiacritics: bool | None = False, ignoreWordOrder: bool | None = False, regex: bool | None = False, randomize: bool | None = False, setName: str | None = None, difficulties: qbreader.types.UnnormalizedDifficulty = None, categories: qbreader.types.UnnormalizedCategory = None, subcategories: qbreader.types.UnnormalizedSubcategory = None, maxReturnLength: int | None = 25, tossupPagination: int | None = 1, bonusPagination: int | None = 1) QueryResponse¶
Query the qbreader database for questions.
Original API doc at https://www.qbreader.org/api-docs/query.
- Parameters:
questionType (qbreader.types.QuestionType) – The type of question to search for. Can be either a string or a question class type.
searchType (qbreader.types.SearchType) – Where to search for the query string. Can only be a string.
queryString (str, optional) – The string to search for.
exactPhrase (bool, default = False) – Ensure that the query string is an exact phrase.
ignoreDiacritics (bool, default = False) – Ignore or transliterate diacritical marks in
queryString.ignoreWordOrder (bool, default = False) – Treat
queryStringas a set of keywords that can appear in any order.regex (bool, default = False) – Treat
queryStringas a regular expression.randomize (bool, default = False) – Randomize the order of the returned questions.
setName (str, optional) – The name of the set to search in.
difficulties (qbreader.types.UnnormalizedDifficulty, optional) – The difficulties to search for. Can be a single or an array of
Difficultyenums, strings, or integers.categories (qbreader.types.UnnormalizedCategory, optional) – The categories to search for. Can be a single or an array of
Categoryenums or strings.subcategories (qbreader.types.UnnormalizedSubcategory, optional) – The subcategories to search for. Can be a single or an array of
Subcategoryenums or strings. The API does not check for consistency between categories and subcategories.maxReturnLength (int, default = 25) – The maximum number of questions to return.
tossupPagination (int, default = 1) – The page of tossups to return.
bonusPagination (int, default = 1) – The page of bonuses to return.
- Returns:
A
QueryResponseobject containing the results of the query.- Return type:
- async random_tossup(difficulties: qbreader.types.UnnormalizedDifficulty = None, categories: qbreader.types.UnnormalizedCategory = None, subcategories: qbreader.types.UnnormalizedSubcategory = None, number: int = 1, min_year: int = Year.MIN_YEAR, max_year: int = Year.CURRENT_YEAR) tuple[Tossup, ...]¶
Get random tossups from the database.
Original API doc at https://www.qbreader.org/api-docs/random-tossup.
- Parameters:
difficulties (qbreader.types.UnnormalizedDifficulty, optional) – The difficulties to search for. Can be a single or an array of
Difficultyenums, strings, or integers.categories (qbreader.types.UnnormalizedCategory, optional) – The categories to search for. Can be a single or an array of
Categoryenums or strings.subcategories (qbreader.types.UnnormalizedSubcategory, optional) – The subcategories to search for. Can be a single or an array of
Subcategoryenums or strings. The API does not check for consistency between categories and subcategories.number (int, default = 1) – The number of tossups to return.
min_year (int, default = Year.MIN_YEAR) – The oldest year to search for.
max_year (int, default = Year.CURRENT_YEAR) – The most recent year to search for.
- Returns:
A tuple of
Tossupobjects.- Return type:
- async random_bonus(difficulties: qbreader.types.UnnormalizedDifficulty = None, categories: qbreader.types.UnnormalizedCategory = None, subcategories: qbreader.types.UnnormalizedSubcategory = None, number: int = 1, min_year: int = Year.MIN_YEAR, max_year: int = Year.CURRENT_YEAR, three_part_bonuses: bool = False) tuple[Bonus, ...]¶
Get random bonuses from the database.
Original API doc at https://www.qbreader.org/api-docs/random-bonus.
- Parameters:
difficulties (qbreader.types.UnnormalizedDifficulty, optional) – The difficulties to search for. Can be a single or an array of
Difficultyenums, strings, or integers.categories (qbreader.types.UnnormalizedCategory, optional) – The categories to search for. Can be a single or an array of
Categoryenums or strings.subcategories (qbreader.types.UnnormalizedSubcategory, optional) – The subcategories to search for. Can be a single or an array of
Subcategoryenums or strings. The API does not check for consistency between categories and subcategories.number (int, default = 1) – The number of bonuses to return.
min_year (int, default = Year.MIN_YEAR) – The oldest year to search for.
max_year (int, default = Year.CURRENT_YEAR) – The most recent year to search for.
three_part_bonuses (bool, default = False) – Whether to only return bonuses with 3 parts.
- Returns:
A tuple of
Bonusobjects.- Return type:
- async random_name() str¶
Get a random adjective-noun pair that can be used as a name.
Original API doc at https://www.qbreader.org/api-docs/random-name.
- Returns:
A string containing the random name.
- Return type:
- async packet(setName: str, packetNumber: int) Packet¶
Get a specific packet from a set.
Original API doc at https://www.qbreader.org/api-docs/packet.
- Parameters:
setName (str) – The name of the set. See
set_list()for a list of valid set names.packetNumber (int) – The number of the packet in the set, starting from 1.
- Returns:
A
Packetobject containing the packet’s tossups and bonuses.- Return type:
- async packet_tossups(setName: str, packetNumber: int) tuple[Tossup, ...]¶
Get only tossups from a packet.
Original API doc at https://www.qbreader.org/api-docs/packet-tossups.
- async packet_bonuses(setName: str, packetNumber: int) tuple[Bonus, ...]¶
Get only bonuses from a packet.
Original API doc at https://www.qbreader.org/api-docs/packet-bonuses.
- async num_packets(setName: str) int¶
Get the number of packets in a set.
Original API doc at https://www.qbreader.org/api-docs/num-packets.
- async set_list() tuple[str, ...]¶
Get a list of all the sets in the database.
Original API doc at https://www.qbreader.org/api-docs/set-list.
- async room_list() tuple[dict, ...]¶
Get a list of public rooms.
Original API doc at https://www.qbreader.org/api-docs/multiplayer/room-list.
- async check_answer(answerline: str, givenAnswer: str) AnswerJudgement¶
Judge an answer to be correct, incorrect, or prompt (can be directed).
Original API doc at https://www.qbreader.org/api-docs/check-answer.
- Parameters:
- Returns:
A
AnswerJudgementobject containing the response.- Return type:
- async tossup_by_id(id: str) Tossup¶
Get a tossup by its ID.
Original API doc at https://www.qbreader.org/api-docs/tossup-by-id.
- class qbreader.Sync¶
Bases:
objectThe synchronous qbreader API wrapper.
- query(questionType: qbreader.types.QuestionType = 'all', searchType: qbreader.types.SearchType = 'all', queryString: str | None = '', exactPhrase: bool | None = False, ignoreDiacritics: bool | None = False, ignoreWordOrder: bool | None = False, regex: bool | None = False, randomize: bool | None = False, setName: str | None = None, difficulties: qbreader.types.UnnormalizedDifficulty = None, categories: qbreader.types.UnnormalizedCategory = None, subcategories: qbreader.types.UnnormalizedSubcategory = None, maxReturnLength: int | None = 25, tossupPagination: int | None = 1, bonusPagination: int | None = 1) QueryResponse¶
Query the qbreader database for questions.
Original API doc at https://www.qbreader.org/api-docs/query.
- Parameters:
questionType (qbreader.types.QuestionType) – The type of question to search for. Can be either a string or a question class type.
searchType (qbreader.types.SearchType) – Where to search for the query string. Can only be a string.
queryString (str, optional) – The string to search for.
exactPhrase (bool, default = False) – Ensure that the query string is an exact phrase.
ignoreDiacritics (bool, default = False) – Ignore or transliterate diacritical marks in
queryString.ignoreWordOrder (bool, default = False) – Treat
queryStringas a set of keywords that can appear in any order.regex (bool, default = False) – Treat
queryStringas a regular expression.randomize (bool, default = False) – Randomize the order of the returned questions.
setName (str, optional) – The name of the set to search in.
difficulties (qbreader.types.UnnormalizedDifficulty, optional) – The difficulties to search for. Can be a single or an array of
Difficultyenums, strings, or integers.categories (qbreader.types.UnnormalizedCategory, optional) – The categories to search for. Can be a single or an array of
Categoryenums or strings.subcategories (qbreader.types.UnnormalizedSubcategory, optional) – The subcategories to search for. Can be a single or an array of
Subcategoryenums or strings. The API does not check for consistency between categories and subcategories.maxReturnLength (int, default = 25) – The maximum number of questions to return.
tossupPagination (int, default = 1) – The page of tossups to return.
bonusPagination (int, default = 1) – The page of bonuses to return.
- Returns:
A
QueryResponseobject containing the results of the query.- Return type:
- random_tossup(difficulties: qbreader.types.UnnormalizedDifficulty = None, categories: qbreader.types.UnnormalizedCategory = None, subcategories: qbreader.types.UnnormalizedSubcategory = None, number: int = 1, min_year: int = Year.MIN_YEAR, max_year: int = Year.CURRENT_YEAR) tuple[Tossup, ...]¶
Get random tossups from the database.
Original API doc at https://www.qbreader.org/api-docs/random-tossup.
- Parameters:
difficulties (qbreader.types.UnnormalizedDifficulty, optional) – The difficulties to search for. Can be a single or an array of
Difficultyenums, strings, or integers.categories (qbreader.types.UnnormalizedCategory, optional) – The categories to search for. Can be a single or an array of
Categoryenums or strings.subcategories (qbreader.types.UnnormalizedSubcategory, optional) – The subcategories to search for. Can be a single or an array of
Subcategoryenums or strings. The API does not check for consistency between categories and subcategories.number (int, default = 1) – The number of tossups to return.
min_year (int, default = Year.MIN_YEAR) – The oldest year to search for.
max_year (int, default = Year.CURRENT_YEAR) – The most recent year to search for.
- Returns:
A tuple of
Tossupobjects.- Return type:
- random_bonus(difficulties: qbreader.types.UnnormalizedDifficulty = None, categories: qbreader.types.UnnormalizedCategory = None, subcategories: qbreader.types.UnnormalizedSubcategory = None, number: int = 1, min_year: int = Year.MIN_YEAR, max_year: int = Year.CURRENT_YEAR, three_part_bonuses: bool = False) tuple[Bonus, ...]¶
Get random bonuses from the database.
Original API doc at https://www.qbreader.org/api-docs/random-bonus.
- Parameters:
difficulties (qbreader.types.UnnormalizedDifficulty, optional) – The difficulties to search for. Can be a single or an array of
Difficultyenums, strings, or integers.categories (qbreader.types.UnnormalizedCategory, optional) – The categories to search for. Can be a single or an array of
Categoryenums or strings.subcategories (qbreader.types.UnnormalizedSubcategory, optional) – The subcategories to search for. Can be a single or an array of
Subcategoryenums or strings. The API does not check for consistency between categories and subcategories.number (int, default = 1) – The number of bonuses to return.
min_year (int, default = Year.MIN_YEAR) – The oldest year to search for.
max_year (int, default = Year.CURRENT_YEAR) – The most recent year to search for.
three_part_bonuses (bool, default = False) – Whether to only return bonuses with 3 parts.
- Returns:
A tuple of
Bonusobjects.- Return type:
- random_name() str¶
Get a random adjective-noun pair that can be used as a name.
Original API doc at https://www.qbreader.org/api-docs/random-name.
- Returns:
A string containing the random name.
- Return type:
- packet(setName: str, packetNumber: int) Packet¶
Get a specific packet from a set.
Original API doc at https://www.qbreader.org/api-docs/packet.
- Parameters:
setName (str) – The name of the set. See
set_list()for a list of valid set names.packetNumber (int) – The number of the packet in the set, starting from 1.
- Returns:
A
Packetobject containing the packet’s tossups and bonuses.- Return type:
- packet_tossups(setName: str, packetNumber: int) tuple[Tossup, ...]¶
Get only tossups from a packet.
Original API doc at https://www.qbreader.org/api-docs/packet-tossups.
- packet_bonuses(setName: str, packetNumber: int) tuple[Bonus, ...]¶
Get only bonuses from a packet.
Original API doc at https://www.qbreader.org/api-docs/packet-bonuses.
- num_packets(setName: str) int¶
Get the number of packets in a set.
Original API doc at https://www.qbreader.org/api-docs/num-packets.
- set_list() tuple[str, ...]¶
Get a list of all the sets in the database.
Original API doc at https://www.qbreader.org/api-docs/set-list.
- room_list() tuple[dict, ...]¶
Get a list of public rooms.
Original API doc at https://www.qbreader.org/api-docs/multiplayer/room-list.
- check_answer(answerline: str, givenAnswer: str) AnswerJudgement¶
Judge an answer to be correct, incorrect, or prompt (can be directed).
Original API doc at https://www.qbreader.org/api-docs/check-answer.
- Parameters:
- Returns:
A
AnswerJudgementobject containing the response.- Return type:
- tossup_by_id(id: str) Tossup¶
Get a tossup by its ID.
Original API doc at https://www.qbreader.org/api-docs/tossup-by-id.
- class qbreader.Tossup(question: str, question_sanitized: str, answer: str, answer_sanitized: str, difficulty: Difficulty, category: Category, subcategory: Subcategory, packet: PacketMetadata, set: SetMetadata, number: int)¶
Bases:
objectTossup class.
- classmethod from_json(json: dict[str, Any]) Self¶
Create a Tossup from a JSON object.
See https://www.qbreader.org/api-docs/schemas#tossups for schema.
- check_answer_sync(givenAnswer: str) AnswerJudgement¶
Check whether an answer is correct.
- async check_answer_async(givenAnswer: str, session: ClientSession | None = None) AnswerJudgement¶
Asynchronously check whether an answer is correct.
- class qbreader.Bonus(leadin: str, leadin_sanitized: str, parts: Sequence[str], parts_sanitized: Sequence[str], answers: Sequence[str], answers_sanitized: Sequence[str], difficulty: Difficulty, category: Category, subcategory: Subcategory, set: SetMetadata, packet: PacketMetadata, number: int, values: Sequence[int] | None = None, difficultyModifiers: Sequence[DifficultyModifier] | None = None)¶
Bases:
objectBonus class.
- classmethod from_json(json: dict[str, Any]) Self¶
Create a Bonus from a JSON object.
See https://www.qbreader.org/api-docs/schemas#bonus for schema.
- check_answer_sync(part: int, givenAnswer: str) AnswerJudgement¶
Check whether an answer is correct.
- async check_answer_async(part: int, givenAnswer: str, session: ClientSession) AnswerJudgement¶
Asynchronously check whether an answer is correct.
- class qbreader.Packet(tossups: Sequence[Tossup], bonuses: Sequence[Bonus], number: int | None = None, name: str | None = None, year: int | None = None)¶
Bases:
objectClass for packets in sets.
- class qbreader.QueryResponse(tossups: Sequence[Tossup], bonuses: Sequence[Bonus], tossups_found: int, bonuses_found: int, query_string: str)¶
Bases:
objectClass for responses to
api/queryrequests.
- class qbreader.AnswerJudgement(directive: Directive, directed_prompt: str | None = None)¶
Bases:
objectA judgement given by
api/check-answer.- classmethod from_json(json: dict[str, Any]) Self¶
Create an AnswerJudgement from a JSON object.
See https://www.qbreader.org/api-docs/check-answer#returns for schema.
- classmethod check_answer_sync(answerline: str, givenAnswer: str) Self¶
Create an AnswerJudgement given an answerline and an answer.
Original API doc at https://www.qbreader.org/api-docs/check-answer.
- async classmethod check_answer_async(answerline: str, givenAnswer: str, session: ClientSession | None = None) Self¶
Asynchronously create an AnswerJudgement given an answerline and an answer.
Original API doc at https://www.qbreader.org/api-docs/check-answer.
- Parameters:
answerline (str) – The answerline to check against. Preferably including the HTML tags <b> and <u>, if they are present.
givenAnswer (str) – The answer to check.
session (aiohttp.ClientSession) – The aiohttp session to use for the request.
- class qbreader.Category(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
StrEnumQuestion category enum.
- LITERATURE = 'Literature'¶
- HISTORY = 'History'¶
- SCIENCE = 'Science'¶
- FINE_ARTS = 'Fine Arts'¶
- RELIGION = 'Religion'¶
- MYTHOLOGY = 'Mythology'¶
- PHILOSOPHY = 'Philosophy'¶
- SOCIAL_SCIENCE = 'Social Science'¶
- CURRENT_EVENTS = 'Current Events'¶
- GEOGRAPHY = 'Geography'¶
- OTHER_ACADEMIC = 'Other Academic'¶
- TRASH = 'Trash'¶
- class qbreader.Subcategory(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
StrEnumQuestion subcategory enum.
- LITERATURE = 'Literature'¶
- HISTORY = 'History'¶
- SCIENCE = 'Science'¶
- FINE_ARTS = 'Fine Arts'¶
- RELIGION = 'Religion'¶
- MYTHOLOGY = 'Mythology'¶
- PHILOSOPHY = 'Philosophy'¶
- SOCIAL_SCIENCE = 'Social Science'¶
- CURRENT_EVENTS = 'Current Events'¶
- GEOGRAPHY = 'Geography'¶
- OTHER_ACADEMIC = 'Other Academic'¶
- TRASH = 'Trash'¶
- AMERICAN_LITERATURE = 'American Literature'¶
- BRITISH_LITERATURE = 'British Literature'¶
- CLASSICAL_LITERATURE = 'Classical Literature'¶
- EUROPEAN_LITERATURE = 'European Literature'¶
- WORLD_LITERATURE = 'World Literature'¶
- OTHER_LITERATURE = 'Other Literature'¶
- AMERICAN_HISTORY = 'American History'¶
- ANCIENT_HISTORY = 'Ancient History'¶
- EUROPEAN_HISTORY = 'European History'¶
- WORLD_HISTORY = 'World History'¶
- OTHER_HISTORY = 'Other History'¶
- BIOLOGY = 'Biology'¶
- CHEMISTRY = 'Chemistry'¶
- PHYSICS = 'Physics'¶
- OTHER_SCIENCE = 'Other Science'¶
- VISUAL_FINE_ARTS = 'Visual Fine Arts'¶
- AUDITORY_FINE_ARTS = 'Auditory Fine Arts'¶
- OTHER_FINE_ARTS = 'Other Fine Arts'¶
- class qbreader.Difficulty(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
StrEnumQuestion difficulty enum.
- UNRATED = '0'¶
- MS = '1'¶
- HS_EASY = '2'¶
- HS_REGS = '3'¶
- HS_HARD = '4'¶
- HS_NATS = '5'¶
- ONE_DOT = '6'¶
- TWO_DOT = '7'¶
- THREE_DOT = '8'¶
- FOUR_DOT = '9'¶
- OPEN = '10'¶