Skip to main content

A Python interface to xkcd.com

By Ben Rosser, released under MIT License (see LICENSE for full text).

This is a Python library for accessing and retrieving links to comics from the xkcd webcomic by Randall Munroe. It is NOT endorsed or made by him, it’s an entirely independent project.

It makes use of the JSON interface to Randall’s site to retrieve comic data. Both Python 2 and Python 3 are supported, and there are no dependencies beyond the Python standard library, so xkcd’s footprint should be very light.

There is support for accessing specific comics, the latest comic, or a random comic. Comic metadata can be queried and the comics themselves can be downloaded onto your local system. The goal is simply to provide a relatively Pythonic wrapper around the xkcd API for any Python program or library that wants to access information about xkcd comics, for one reason or another.

The xkcd module, as of version 2.4.0, also supports getting information on What If articles from whatif.xkcd.com. This information is generated by scraping the What If archive page with a HTML parser.

Full API documentation is available here.

Changelog:

Version 2.4.2:

  • Switched to using HTTPS URLs for all xkcd queries.

Version 2.4.1:

  • Routines that take comic/article numbers (e.g. xkcd.getComic()) now also can take strings containing cardinal numbers.

Version 2.4.0:

  • Added preliminary What If support; routines for querying basic data about What If articles now exist.

  • Comic.download() will create its default directory (~/Downloads) if it does not already exist, rather than simply failing.

  • All prints to standard output are now wrapped in “silent” options that now default to True (this affects xkcd.getComic and Comic.download); if silent is set, output won’t be printed.

  • Significantly improved documentation for all available functions and classes.

Version 2.3.3:

  • Made pypandoc conversion optional; long_description will be MD formatted if it cannot be imported (and rST-formatted if it can).

Version 2.3.2:

  • Fixed distutils URL to point at TC01/python-xkcd, not TC01/xkcd.

  • Started using pypandoc to dynamically turn README.md into a RST long-description.

Version 2.3:

  • Fixed ASCII bug in Python 2.x

  • Created Sphinx documentation and uploaded it to pythonhosted.org

Version 2.2:

  • Fixed very silly bug with xkcd.getComic()

  • Added a getExplanation() which returns an explainxkcd link for a Comic().

  • Added support for Python 3!

Version 2.1:

  • Fixed bugs with Comic.download() function

  • Added optional parameter to Comic.download() to change name of output file

  • Added more information to long_description text

Credits:

Contributions from (github users, unless indicated otherwise):

  • @Kyu

  • Tanya Sandoval (@tsando)

Metadata

Release files for xkcd 2.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xkcd 2.4.2
File Size Uploaded Provenance
xkcd-2.4.2.tar.gz 10.1 kB Without provenance Details

Release files / xkcd-2.4.2.tar.gz

Download URL xkcd-2.4.2.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
180cee51fd1733288448cd8551e36680b14811003287fe9ccf61888538dd0970
BLAKE2b-256 checksum
How to use checksums
f8dc8e9824517b9fbc42f6d95a1a5d345c6b9e6dd885ec3a301953ac7c2fb4d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for xkcd 2.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page