Skip to main content

An API wrapper for interacting with the OpenTDB API.

Project description

OpenTDBpy

An API wrapper for interacting with the OpenTDB API.

Introduction

In order to being working with this API, you must create a client.

import opentdbpy

client = opentdbpy.Client()

Functionality

There are two main components when working with the client.

client.get_categories()
client.get_category()

or

client.get_questions()

When you make a call with get_categories(), the entries are cached for each time it is used. The same applies when using get_category().

Note: The cache is cleared every hour.

Using get_categories() will return a list of Category objects. Using get_category() can take 2 possible arguments. Which are the id and name. You can pass either or, and even both. This will return a Category object containing useful information about the category. If there are no results, the return value will be None.

When you wish to get questions from the api, use get_questions().

There are four possible arguments you can pass. These include: amount, category, type, and use_token.

By default, using this function will not use your session token. Setting use_token to true will use it.

This will require you to either pass in a previous session token, or generate a new one with get_token().

The amount takes an integer, which will return that number of questions. The category takes either an integer or a string, you can pass in the category id or the name. The type takes a string, which determines the question type.

Tokens

In OpenTDB, tokens are used to filter out questions you have already pulled.

If you wish to use a token, you can either manually create one and pass it into Client. Or, you can use client.get_token() to create a new one.

If your client has a session token and you wish to reset it's data, use reset_token().

If you want to change your session token to a manual one on runtime, you can use set_token(). If you don't want to manually create a session token, run get_token() to pull a new one automatically.

Project details


Download files

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

Files for opentdbpy, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size opentdbpy-1.0.2-py3-none-any.whl (7.1 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size opentdbpy-1.0.2.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page