xkcd.py

Installation

Python 3.8 or higher is required.

To install the stable version, do the following:

# Unix / macOS
python3 -m pip install "xkcd.py"

# Windows
py -m pip install "xkcd.py"

To install the development version, do the following:

$ git clone https://github.com/Infiniticity/xkcd.py

Make sure you have the latest version of Python installed, or if you prefer, a Python version of 3.8 or greater.

If you have have any other issues feel free to search for duplicates and then create a new issue on GitHub with as much detail as possible. Include the output in your terminal, your OS details and Python version.

Comic

class xkcd.Comic(number: Optional[int] = None, *, random: Optional[bool] = False)

A class that represents a comic.

Parameters
  • number (Optional[int]) – The comic’s number.

  • random (Optional[bool]) – Whether to choose a random comic, or not.

Note

If random is True, number must not be specified.

Variables
  • date – The comic’s date.

  • image – The URL of the comic’s image.

  • number – The number of the comic.

  • title – The comic’s title.

  • safe_title – A safe form of the comic’s title.

  • transcript – The trascript of the comic.

  • wiki_url – The URL of the comic’s wiki.

  • url – The comic’s URL.

class Image(_url: str, _title: str)

A class that represents an image.

Variables
  • url – The image’s URL.

  • title – The image’s title (Alt Text).

  • filename – The filename of the image.

What If Article

class xkcd.WhatIfArticle(number: Optional[int] = None, *, random=False)

A class that represents a What If article.

Parameters
  • number (Optional[int]) – The article’s number.

  • random (Optional[bool]) – Whether to choose a random article, or not.

Note

If random is True, number must not be specified.

Variables
  • entry – The article entry. It is a list of str, Image, Hyperlink and Reference.

  • number – The number of the article.

  • title – The article’s title.

  • question – The question of the article.

  • author – The author of the article.

  • url – The article’s URL.

A class that represents hyperlinked text.

Variables
  • url – The URL that hyperlink leads to.

  • text – The text shown on the hyperlink.

class Image(_url: str, _title: str)

A class that represents an image.

Variables
  • url – The image’s URL.

  • title – The image’s title (Alt Text).

  • filename – The filename of the image.

class Reference(_number: int, _text: str)

A class that represents a reference.

Variables
  • number – The reference’s number.

  • text – The text shown upon hovering over the reference.