Open In App

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:



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

Step 4: After that, you will be redirected to their terms of use page for the API. Just scroll down to the bottom (or you can give it a read if you want) and click on accept. Now, there we go, finally we will arrive at the page where it will show you the two most important keys and other important information. Just copy the Private and the public keys and store them in a secured folder on your computer. The page will look like this

Note: Keep these keys in a private folder and don’t share them with anyone else. 

Approach:

from marvel import Marvel
m = Marvel(PUBLIC_KEY, PRIVATE_KEY)

characters = m.characters comics = m.comics creators = m.creators events = m.events series = m.series stories = m.stories

# where x is the serial code of your 
# superhero
comics = characters.comics(1011334)

Below is the implementation:




# importing the marvel module
from marvel import Marvel
 
m = Marvel("8e6845d48fcb5b7dbec2bc3784b9d2be",
           "2a6e5c6ad9fb7000cbee68c881b0c8c816bc9eb7")
 
# getting the characters object
characters = m.characters
 
# serial code of your favourite character
# this can be different according to your preference
x = 1011334
for n in range (0, 6):
   
      # search for comics of this character
    all_characters=characters.comics(x)
     
    x = x+1
    for i in range (1,12):
      print(all_characters['data']['results'][int(i)]['title'])

Output:


Article Tags :