TechnologyWebsite BuildersWordPress Hosting

How To Use IndexNow API With Python For Bulk Indexing

IndexNow is a protocol developed by Microsoft Bing and adopted by Yandex that allows site owners and web optimization professionals to simply notify engines like google when a webpage has been up to date through an API.

And right now, Microsoft introduced that it’s making the protocol simpler to implement by making certain that submitted URLs are shared between engines like google.

Given its constructive implications and the promise of a quicker indexing expertise for publishers, the IndexNow API must be on each web optimization skilled’s radar.

Utilizing Python for automating URL submission to the IndexNow API or making an API request to the IndexNow API for bulk URL indexing could make managing IndexNow extra environment friendly for you.


On this tutorial, you’ll discover ways to just do that, with step-by-step directions for utilizing the IndexNow API to submit URLs to Microsoft Bing in bulk with Python.

Be aware: The IndexNow API is just like Google’s Indexing API with just one distinction: the Google Indexing API is just for job ads or broadcasting net pages that include a video object inside it.

Google introduced that they are going to take a look at the IndexNow API however hasn’t up to date us since.

Bulk Indexing Utilizing IndexNow API with Python: Getting Began

Under are the requirements to grasp and implement the IndexNow API tutorial.


Under are the Python packages and libraries that will probably be used for the Python IndexNow API tutorial.

  • Advertools (should).
  • Pandas (should).
  • Requests (should).
  • Time (non-compulsory).
  • JSON (non-compulsory).

Earlier than getting began, reading the basics will help you to grasp this IndexNow API and Python tutorial higher. We will probably be utilizing an API Key and a .txt file to offer authentication together with particular HTTP Headers.

IndexNow API Usage with PythonIndexNow API Utilization Steps with Python.

1. Import The Python Libraries

To use the required Python libraries, we’ll use the “import” command.

  • Advertools will probably be used for sitemap URL extraction.
  • Requests will probably be used for making the GET and POST requests.
  • Pandas will probably be used for taking the URLs within the sitemap into a listing object.
  • The “time” module is to forestall a “An excessive amount of request” error with the “sleep()” methodology.
  • JSON is for presumably modifying the POST JSON object if wanted.

Under, you can find all the mandatory import traces for the IndexNow API tutorial.

import advertools as adv
import pandas as pd
import requests
import json
import time

2. Extracting The Sitemap URLs With Python

To extract the URLs from a sitemap file, completely different net scraping strategies and libraries can be utilized akin to Requests or Scrapy.

However to maintain issues easy and environment friendly, I’ll use my favourite Python web optimization bundle – Advertools.

With solely a single line of code, all the URLs inside a sitemap might be extracted.

sitemap_urls = adv.sitemap_to_df(“”)

The “sitemap_to_df” methodology of the Advertools can extract all of the URLs and different sitemap-related tags akin to “lastmod” or “precedence.”

Under, you possibly can see the output of the “adv.sitemap_to_df” command.

Sitemap URL Extraction for IndexNow API UsageSitemap URL Extraction might be performed through Advertools’ “sitemap_to_df” methodology.

All the URLs and dates are specified inside the “sitemap_urls” variable.

Since sitemaps are helpful sources for engines like google and SEOs, Advertools’ sitemap_to_df method can be utilized for a lot of completely different duties together with a Sitemap Python Audit.

However that’s a subject for one more time.

3. Take The URLs Into A Checklist Object With “to_list()”

Python’s Pandas library has a technique for taking a knowledge body column (information sequence) into a listing object, to_list().

Under is an instance utilization:


Under, you possibly can see the outcome:

Sitemap URL ListingPandas’ “to_list” methodology can be utilized with Advertools for itemizing the URLs.

All URLs inside the sitemap are in a Python record object.

4. Perceive The URL Syntax Of IndexNow API Of Microsoft Bing

Let’s check out the URL syntax of the IndexNow API.

Right here’s an instance:


The URL syntax represents the variables and their relations to one another inside the RFC 3986 requirements.

  • The <searchengine> represents the search engine title that you’ll use the IndexNow API for.
  • “?url=” parameter is to find out the URL that will probably be submitted to the search engine through IndexNow API.
  • “&key=” is the API Key that will probably be used inside the IndexNow API.
  • “&keyLocation=” is to offer an authenticity that reveals that you’re the proprietor of the web site that IndexNow API will probably be used for.

The “&keyLocation” will deliver us to the API Key and its “.txt” model.

5. Collect The API Key For IndexNow And Add It To The Root

You’ll want a sound key to make use of the IndexNow API.

Use this link to generate the Microsoft Bing IndexNow API Key.

IndexNow API Key Taking There isn’t a restrict for producing the IndexNow API Key.

Clicking the “Generate” button creates an IndexNow API Key.

While you click on on the obtain button, it is going to obtain the “.txt” model of the IndexNow API Key.

IndexNow API Key GenerationIndexNow API Key might be generated by Microsoft Bing’s acknowledged tackle.txt version of IndexNow API KeyDownloaded IndexNow API Key as txt file.

The TXT model of the API key would be the file title and in addition to inside the textual content file.

IndexNow API Key in TXT FileIndexNow API Key in TXT File must be the identical with the title of the file, and the precise API Key worth.

The subsequent step is importing this TXT file to the basis of the web site’s server.

Since I take advantage of FileZilla for my FTP, I’ve uploaded it simply to my net server’s root.

Root Server and IndexNow API Set upBy placing the .txt file into the online server’s root folder, the IndexNow API setup might be accomplished.

The subsequent step is performing a easy for a loop instance for submitting all the URLs inside the sitemap.

6. Submit The URLs Inside The Sitemap With Python To IndexNow API

To submit a single URL to the IndexNow, you should use a single “requests.get()” occasion. However to make it extra helpful, we’ll use a for a loop.

To submit URLs in bulk to the IndexNow API with Python, comply with the steps beneath:

  • Create a key variable with the IndexNow API Key worth.
  • Change the <searchengine> part with the search engine that you simply wish to submit URLs (Microsoft Bing, or Yandex, for now).
  • Assign all the URLs from the sitemap inside a listing to a variable.
  • Use the “txt” file inside the root of the online server with its URL worth.
  • Place the URL, key, and key location URL inside the string manipulation worth.
  • Begin your for a loop, and use the “requests.get()” for all the URLs inside the sitemap.
  • Under, you possibly can see the implementation:

    key = “22bc7c564b334f38b0b1ed90eec8f2c5”
    url = sitemap_urls[“loc”].to_list()for i in url:
              endpoint = f”{i}&key={key}&keyLocation={location}”
              response = requests.get(endpoint)
              print(response.status_code, response.content material)

    When you’re involved about sending too many requests to the IndexNow API, you should use the Python time module to make the script wait between each request.

    Right here you possibly can see the output of the script:

    IndexNow API Automation ScriptThe empty string because the request’s response physique represents the success of the IndexNow API request based on Microsoft Bing’s IndexNow documentation.

    The 200 Standing Code implies that the request was profitable.

    With the for a loop, I’ve submitted 194 URLs to Microsoft Bing.

    Based on the IndexNow Documentation, the HTTP 200 Response Code indicators that the search engine is conscious of the change within the content material or the brand new content material. Nevertheless it doesn’t essentially assure indexing.

    For occasion, I’ve used the identical script for one more web site. After 120 seconds, Microsoft Bing says that 31 outcomes are discovered. And conveniently, it reveals 4 pages.

    The one downside is that on the primary web page there are solely two outcomes, and it says that the URLs are blocked by Robots.txt even when the blocking was eliminated earlier than submission.

    This will occur if the robots.txt was modified to take away some URLs earlier than utilizing the IndexNow API as a result of evidently Bing doesn’t verify the Robots.txt once more.

    Thus, in case you beforehand blocked them, they attempt to index your web site however nonetheless use the earlier model of the robots.txt file.

    Bing IndexNow API ResultsIt reveals what’s going to occur in case you use IndexNow API by blocking Bingbot through Robots.txt.

    On the second web page, there is just one outcome:

    IndexNow Bing Paginated ResultMicrosoft Bing would possibly use a unique indexation and pagination methodology than Google. The second web page reveals just one among the many 31 outcomes.

    On the third web page, there is no such thing as a outcome, and it reveals the Microsoft Bing Translate for translating the string inside the search bar.

    Microsoft Bing TranslateIt reveals generally, Microsoft Bing infers the “website” search operator as part of the question.

    After I checked Google Analytics, it reveals that Bing nonetheless hadn’t crawled the web site or listed it. I do know that is true as I additionally checked the log information.

    Google and Bing Indexing ProcessesUnder, you will note the Bing Webmaster Software’s report for the instance web site:

    Bing Webmaster Tools Report

    It says that I submitted 38 URLs.

    The subsequent step will contain the majority request with the POST Methodology and a JSON object.

    7. Carry out An HTTP Publish Request To The IndexNow API

    To carry out an HTTP put up request to the IndexNow API for a set of URLs, a JSON object must be used with particular properties.

    • Host property represents the search engine hostname.
    • Key represents the API Key.
    • Key represents the placement of the API Key’s txt file inside the net server.
    • urlList represents the URL set that will probably be submitted to the IndexNow API.
    • Headers signify the POST Request Headers that will probably be used that are “Content material-type” and “charset.”

    Since this can be a POST request, the “requests.put up” will probably be used as a substitute of the “requests.get().”

    Under, you can find an instance of a set of URLs submitted to Microsoft Bing’s IndexNow API.

    information = {
      “host”: “”,
      “key”: “22bc7c564b334f38b0b1ed90eec8f2c5”,
      “keyLocation”: “”,
      “urlList”: [
          ] }
    headers = {“Content material-type”:”utility/json”, “charset”:”utf-8″}
    r = requests.put up(“”, information=information, headers=headers)
    r.status_code, r.content material

    Within the instance above, now we have carried out a POST Request to index a set of URLs.

    We’ve used the “information” object for the “information parameter of requests.put up,” and the headers object for the “headers” parameter.

    Since we POST a JSON object, the request ought to have the “content-type: utility/json” key and worth with the “charset:utf-8.”

    After I make the POST request, 135 seconds later, my reside logfile evaluation dashboard began to indicate the quick hits from the Bingbot.

    Bingbot Log File Analysis

    8. Create Customized Operate For IndexNow API To Make Time

    Making a customized operate for IndexNow API is beneficial to lower the time that will probably be spent on the code preparation.

    Thus, I’ve created two completely different customized Python capabilities to make use of the IndexNow API for bulk requests and particular person requests.

    Under, you can find an instance for under the majority requests to the IndexNow API.

    The customized operate for bulk requests is named “submit_url_set.”

    Even in case you simply fill within the parameters, nonetheless it is possible for you to to make use of it correctly.

    def submit_url_set(set_:record, key, location, host=””, headers={“Content material-type”:”utility/json”, “charset”:”utf-8″}):
         key = “22bc7c564b334f38b0b1ed90eec8f2c5”
         set_ = sitemap_urls[“loc”].to_list()
         information = {
         “host”: “”,
         “key”: key,
         “keyLocation”: “”,
         “urlList”: set_
         r = requests.put up(host, information=information, headers=headers)
         return r.status_code

    A proof of this practice operate:

    • The “Set_” parameter is to offer a listing of URLs.
    • “Key” parameter is to offer an IndexNow API Key.
    • “Location” parameter is to offer the placement of the IndexNow API Key’s txt file inside the net server.
    • “Host” is to offer the search engine host tackle.
    • “Headers” is to offer the headers which might be mandatory for the IndexNow API.

    I’ve outlined a few of the parameters with default values akin to “host” for Microsoft Bing. If you wish to use it for Yandex, you will have to state it whereas calling the operate.

    Under is an instance utilization:

    submit_url_set(set_=sitemap_urls[“loc”].to_list(), key=”22bc7c564b334f38b0b1ed90eec8f2c5″, location=””)

    If you wish to extract sitemap URLs with a unique methodology, or if you wish to use the IndexNow API for a unique URL set, you will have to vary “set_” parameter worth.

    Under, you will note an instance of the Customized Python operate for the IndexNow API for under particular person requests.

    def submit_url(url, location, key = “22bc7c564b334f38b0b1ed90eec8f2c5”):
         key = “22bc7c564b334f38b0b1ed90eec8f2c5”
         url = sitemap_urls[“loc”].to_list()
         for i in url:
              endpoint = f”{i}&key={key}&keyLocation={location}”
              response = requests.get(endpoint)
              print(response.status_code, response.content material)

    Since that is for a loop, you possibly can submit extra URLs one after the other. The search engine can prioritize these kind of requests in a different way.

    Among the bulk requests will embody non-important URLs, the person requests may be seen as extra affordable.

    If you wish to embody the sitemap URL extraction inside the operate, it’s best to embody Advertools naturally into the capabilities themselves.

    Suggestions For Utilizing The IndexNow API With Python

    An Overview of How The IndexNow API Works, Capabilities & Makes use of

    • The IndexNow API doesn’t assure that your web site or the URLs that you simply submitted will probably be listed.
    • It is best to solely submit URLs which might be new or for which the content material has modified.
    • The IndexNow API impacts the crawl finances.
    • Microsoft Bing has a threshold for the URL Content material High quality and Calculation of the Crawl Want for a URL. If the submitted URL just isn’t ok, they could not crawl it.
    • You may submit as much as 10,000 URLs.
    • The IndexNow API suggests submitting URLs even when the web site is small.
    • Submitting the identical pages many occasions inside a day can block the IndexNow API from crawling the redundant URLs or the supply.
    • The IndexNow API is beneficial for websites the place the content material adjustments steadily, like each 10 minutes.
    • IndexNow API is beneficial for pages which might be gone and are returning a 404 response code. It lets the search engine know that the URLs are gone.
    • IndexNow API can be utilized for notifying of latest 301 or 302 redirects.
    • The 200 Standing Response Code implies that the search engine is conscious of the submitted URL.
    • The 429 Standing Code implies that you made too many requests to the IndexNow API.
    • When you put a “txt” file that accommodates the IndexNow API Key right into a subfolder, the IndexNow API can be utilized just for that subfolder.
    • When you have two completely different CMS, you should use two completely different IndexNow API Keys for 2 completely different website sections
    • Subdomains want to make use of a unique IndexNow API key.
    • Even in case you already use a sitemap, utilizing IndexNow API is beneficial as a result of it effectively tells the major search engines of web site adjustments and reduces pointless bot crawling.
    • All engines like google that undertake the IndexNow API (Microsoft Bing and Yandex) share the URLs which might be submitted between one another.

    IndexNow API Infographic SEOIndexNow API Documentation and utilization ideas might be discovered above.

    On this IndexNow API tutorial and guideline with Python, now we have examined a brand new search engine know-how.

    As an alternative of ready to be crawled, publishers can notify the major search engines to crawl when there’s a want.

    IndexNow reduces the usage of search engine information heart sources, and now you know the way to make use of Python to make the method extra environment friendly, too.

    Extra sources:

    An Introduction To Python & Machine Studying For Technical web optimization

    How to Use Python to Monitor & Measure Web site Efficiency

    Superior Technical web optimization: A Full Information

    Featured Picture: metamorworks/Shutterstock

    Show More

    Related Articles

    Leave a Reply

    Your email address will not be published. Required fields are marked *