A Python wrapper for the XKCD webcomic API. Because sometimes you need comics in your code.
Features
Get XKCD comics by number, or just ask for the latest and hope it’s not about Python.
Search comics by title or transcript (for when you remember the joke but not the number).
Pythonic interface, because we like snakes.
Type hints, so your editor can feel smart.
Error handling, because the internet is a scary place.
Documentation and examples, so you don’t have to read the source (unless you want to).
Requirements
Python 3.8 or higher (older Pythons are like old comics: fun, but not supported)
requests (for talking to the internet)
Installation
To install the latest stable version:
# Unix / macOS
python3 -m pip install "xkcd.py"
# Windows
py -m pip install "xkcd.py"
To install the development version (for people who like living on the edge):
git clone https://github.com/Ombucha/xkcd.py
cd xkcd.py
python3 -m pip install -e .
Getting Started
Install the package (see above).
Start coding! (see below)
Quick Example
import xkcd
# Get the latest comic (fingers crossed it's not about regular expressions)
comic = xkcd.Comic()
print(f"{comic.number}: {comic.title} - {comic.image.url}")
# Get a specific comic by number (353 is a classic)
comic = xkcd.Comic(353)
print(f"{comic.number}: {comic.title} - {comic.image.title}")
# Search for comics about Python (the language, not the snake)
results = xkcd.search("Python")
for comic in results:
print(f"{comic.number}: {comic.title}")
Links
xkcd (the source of all stick-figure wisdom)
Official API (for robots)
Documentation (for humans)
Contributing
Pull requests, issues, and stick-figure diagrams welcome! See the contributing guide.
License
MIT License. Because sharing is caring. See the LICENSE file for details.
Metadata
Release files for xkcd.py 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| xkcd_py-1.3.0.tar.gz | 9.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xkcd_py-1.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.8 kB
Release files / xkcd_py-1.3.0.tar.gz
| Download URL | xkcd_py-1.3.0.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6eaebf1a733e137642781757471802673db1b5321c4d2db48334a838e6b9f8c0
|
|
BLAKE2b-256 checksum How to use checksums |
79923fd39f82d22f3df4b73566ba2dd26540506b047969e79bbe47dc661ddad3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.23
|
Release files / xkcd_py-1.3.0-py3-none-any.whl
| Download URL | xkcd_py-1.3.0-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0084dd69414df6ec3fb7a2b3f5a491baa3a4475fc85c62fe2f310ef6a22ac0a9
|
|
BLAKE2b-256 checksum How to use checksums |
e9f0e6eda24ad991412e965f1a454db9f47de76b656d06eb8f6028ddfa00f4f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.23
|