Effortlessly Creating Quizzes with the Quizgecko Quiz API: A Python Tutorial

Quizgecko, an advanced online quiz and assessment maker, leverages AI capabilities to automatically generate questions and assessments from any given text or document. Its developer API facilitates the integration of its quiz generation function into your own software.

This guide will show you how to exploit Quizgecko's API, using Python and the requests library, for automated quiz creation.

Getting

To start with, sign up for a free Quizgecko account at quizgecko.com. After you've successfully registered, navigate to the API page and generate your unique API key.

Subsequently, you'll need to install the requests library using the following command:

pip install requests

Once installed, import the requests library into your Python environment:

import requests

Next, save your API key as a variable for future use:

api_key = 'YOUR_API_KEY'

Producing Quizzes

To produce a quiz, a POST request is made to the /questions endpoint. This requires your API key (included in the headers) and the text to generate questions from (included in the request body):

url = 'https://quizgecko.com/api/v1/questions'

text = "Isaac Newton was an English mathematician, physicist, astronomer, theologian, and author who is widely recognised as one of the greatest mathematicians and most influential scientists of all time."

headers = {
'Authorization': f'Bearer {api_key}'
}

data = {
'text': text
}

response = requests.post(url, headers=headers, json=data)

This process will initiate an asynchronous generation of a multiple-choice quiz based on the text you've supplied.

To continuously check for the readiness of the quiz, make GET requests to the /quiz/{id} endpoint, using the id returned in the previous response:

quiz_id = response.json()['quiz']['id']

url = f'https://quizgecko.com/api/v1/quiz/{quiz_id}'

while True:
response = requests.get(url, headers=headers)
if response.json()['status'] == 'completed':
break
time.sleep(5)

print(response.json()['questions'])

Utilizing Additional Capabilities

The Quizgecko API offers a rich set of functionalities, including:

  • Generating quizzes from URLs and files simply by passing the link or file
  • Accessing quiz results and analytics
  • Creating quizzes in numerous languages
  • These represent just a snapshot of what's possible; the full API documentation provides comprehensive details.

Wrapping Up

The Quizgecko API empowers you to incorporate AI-driven quiz and assessment generation into your Python applications effortlessly. Register for a free account, secure an API key, and streamline your quiz creation process today!

AiPythonApi
Avatar for James Blackwell

Written by James Blackwell

Founder and CEO of Quizgecko

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.