A basic API wrapper for xkcd.
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xkcd_py-1.3.0.tar.gz.
File metadata
- Download URL: xkcd_py-1.3.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6eaebf1a733e137642781757471802673db1b5321c4d2db48334a838e6b9f8c0
|
|
| MD5 |
e76d40f9d6801f3b5e81cae3897ba718
|
|
| BLAKE2b-256 |
79923fd39f82d22f3df4b73566ba2dd26540506b047969e79bbe47dc661ddad3
|
File details
Details for the file xkcd_py-1.3.0-py3-none-any.whl.
File metadata
- Download URL: xkcd_py-1.3.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0084dd69414df6ec3fb7a2b3f5a491baa3a4475fc85c62fe2f310ef6a22ac0a9
|
|
| MD5 |
0ec5194d5667130c229a2468b9ae9b99
|
|
| BLAKE2b-256 |
e9f0e6eda24ad991412e965f1a454db9f47de76b656d06eb8f6028ddfa00f4f8
|