Find comics of marvel superhero using marvel API in Python
In this article, we will find the comic of marvel by using python and marvel api. Marvel has provided an API that provides a look into their database consisting of various comics, movies, etc. We will be using that to find out your favorite marvel superhero comic books.
The Marvel Comics API is a tool to help developers everywhere create amazing, uncanny, and incredible websites and applications using data from the 70-plus years of the Marvel age of comics.
The Marvel Comics API is a RESTful service that provides methods for accessing specific resources at canonical URLs and for searching and filtering sets of resources by various criteria. All representations are encoded as JSON objects.
You can access six resource types using the API:
- Comics: individual print and digital comic issues, collections, and graphic novels. For example: Amazing Fantasy #15.
- Comic series: sequentially numbered (well, mostly sequentially numbered) groups comics with the same title. For example, Uncanny X-Men.
- Comic stories: indivisible, reusable components of comics. For example, the cover from Amazing Fantasy #15 or the origin of the Spider-Man story from that comic.
- Comic events and crossovers: big, universe-altering storylines. For example, Infinity
- Creators: women, men, and organizations who create comics. For example, Jack Kirby.
- Characters: the women, men, organizations, alien species, deities, animals, non-corporeal entities, trans-dimensional manifestations, abstract personifications, and green amorphous blobs which occupy the Marvel Universe (and various alternate universes, timelines, and altered realities therein). For example, Spider-Man.
In this article, we will try to fetch a particular character from the marvel API, and then we will generate the comics in which that particular character appeared.
Installation of marvel package
pip install marvel
Getting the api key:
Step 1: First go their website https://developer.marvel.com/, Now click on to top left “SIGN IN | JOIN” option and then click on to the “CREATE AN ACCOUNT” and now give your details and then click “CREATE ACCOUNT” option, which will look like this
Step 2: After signing in you will be redirected to their home page where it will show that your account is now logged in, but in order to get the API key first, you’ve to confirm the mail which marvel has sent you on your specified email address in order to verify it. Check your mailbox there will be a mail sent by marvel. Open it and then click “Confirm” option
Step 3: After that, you’ve to come back to your marvel developer portal where you’ve just created your account, and now on the top left side it will show your username instead of the sign-in option otherwise please refer to the steps again. After that in the middle center portion of the website, you will find an option “Get a Key”, click on that
Note: Keep these keys in a private folder and don’t share them with anyone else.
- First import marvel from Marvel package
from marvel import Marvel
- After that type your public and private keys like this
m = Marvel(PUBLIC_KEY, PRIVATE_KEY)
- Now there are six objects presented namely, characters, comics, creators, events, series and stories. Check : https://pypi.org/project/marvel/ for more info
characters = m.characters comics = m.comics creators = m.creators events = m.events series = m.series stories = m.stories
- Each of the above objects returns the appropriate response (JSON), but from here we are only interested in getting the characters object which is the first one.
- Now every superhero has a serial number associated with it, find out about a rare superhero named “3-D Man” and discover his comics.
- For getting the comics we have syntax like this
# where x is the serial code of your # superhero comics = characters.comics(1011334)
- We will store this comics dictionary as all_characters dictionary in our code
Below is the implementation: