A wrapper for the xkcd API
Project description
xkcd-wrapper
A Python wrapper for the xkcd webcomic API.
Retrieves xkcd comic data and metadata as python objects.
Asynchronous (async) and synchronous implementations.
Installation
At the command line, with pip
:
$ pip install xkcd-wrapper
Usage
>>> import xkcd_wrapper
>>> client = xkcd_wrapper.Client()
>>> specific_comic = client.get(100) # Comic object with comic 100 data
>>> latest_comic = client.get_latest() # Comic object containing data of the latest xkcd comic
>>> random_comic = client.get_random() # Comic object of a random comic
>>> specific_comic
xkcd_wrapper.Comic(100)
>>> specific_comic.image
'https://imgs.xkcd.com/comics/family_circus.jpg'
async:
>>> import xkcd_wrapper, asyncio
>>> async_client = xkcd_wrapper.AsyncClient()
>>> async def async_call():
... responses = await asyncio.gather(
... async_client.get(100), # Comic object with comic 100 data
... async_client.get_latest(), # Comic object containing data of the latest xkcd comic
... async_client.get_random() # Comic object of a random comic
... )
... print(
... responses[0], # async_client.get(100) output
... responses[0].image,
... sep='\n'
... )
>>> asyncio.run(async_call())
xkcd_wrapper.Comic(100)
'https://imgs.xkcd.com/comics/family_circus.jpg'
Documentation
Check the documentation for more details: https://xkcd-wrapper.readthedocs.io/en/latest
Ideas for the Future
- retrieve comic .jpeg
History
0.2.0 (08-08-2020)
- Async implementation
0.1.0 (23-04-2020)
- First release on PyPI
- Client and Comic classes
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
xkcd-wrapper-0.2.0.tar.gz
(7.0 kB
view hashes)
Built Distribution
Close
Hashes for xkcd_wrapper-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cef4f9a15ffa3e96ddb82142d5cbddf2de1931e7889feeb0d20a373a1d1e87c |
|
MD5 | b6936c1242c788a3d2f3f90cd6ae82e5 |
|
BLAKE2b-256 | 992f27e47d35d06403ef2211229d9a8aab2206a6908d5d7256a9dde3c49db0a0 |