Skip to content

Submit Multiple Sitemaps to the IndexNow API#

submit_sitemaps_to_index_now()#

Submit multiple sitemaps to the IndexNow API of a search engine.

Parameters:

Name Type Description Default
authentication IndexNowAuthentication

Authentication credentials for the IndexNow API.

required
sitemap_locations list[str]

List of sitemap locations to submit, e.g. ["https://example.com/sitemap1.xml", "https://example.com/sitemap2.xml, "https://example.com/sitemap3.xml"].

required
filter SitemapFilter | None

Optional filter for URLs. Ignored by default or if set to None.

None
endpoint SearchEngineEndpoint | str

Select the search engine you want to submit to or use a custom URL as endpoint.

INDEXNOW

Returns:

Name Type Description
int int

Status code of the response, e.g. 200 or 202 for, respectively, success or accepted, or 400 for bad request, etc.

Example

After adding your authentication credentials to the IndexNowAuthentication class, you can now submit multiple sitemaps to the IndexNow API:

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from index_now import submit_sitemaps_to_index_now, IndexNowAuthentication

authentication = IndexNowAuthentication(
    host="example.com",
    api_key="a1b2c3d4",
    api_key_location="https://example.com/a1b2c3d4.txt",
)

sitemap_locations = [
    "https://example.com/sitemap1.xml",
    "https://example.com/sitemap2.xml",
    "https://example.com/sitemap3.xml",
]

submit_sitemaps_to_index_now(authentication, sitemap_locations)

If you want to submit to a specific search engine, alternatively customize the endpoint:

15
16
submit_sitemaps_to_index_now(authentication, sitemap_location,
    endpoint="https://www.bing.com/indexnow")

If you want to only upload a portion of the sitemap URLs, apply the skip and take parameters in the SitemapFilter class:

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from index_now import submit_sitemaps_to_index_now, IndexNowAuthentication, SitemapFilter

authentication = IndexNowAuthentication(
    host="example.com",
    api_key="a1b2c3d4",
    api_key_location="https://example.com/a1b2c3d4.txt",
)

sitemap_locations = [
    "https://example.com/sitemap1.xml",
    "https://example.com/sitemap2.xml",
    "https://example.com/sitemap3.xml",
]

filter = SitemapFilter(skip=100, take=50)

submit_sitemaps_to_index_now(authentication, sitemap_location, filter)

Instead of filtering by amount, you can filter by last modified date using the date_range parameter. Firstly, add one of the date range options to the imports, e.g. DaysAgo:

1
from index_now import DaysAgo, submit_sitemaps_to_index_now, IndexNowAuthentication, SitemapFilter

Then use the date_range parameter to filter URLs by last modified date:

15
filter = SitemapFilter(date_range=DaysAgo(2))

Or target URLs with a specific pattern using the contains parameter:

15
filter = SitemapFilter(contains="section1")

The contains parameter also accepts regular expressions for more advanced filtering:

15
filter = SitemapFilter(contains=r"(section1)|(section2)")

Or use the excludes parameter to exclude URLs that match a specific pattern:

15
filter = SitemapFilter(excludes="page1")

Or combine all the contains and excludes, skip and take, date_range and other parameters to filter the URLs even further:

15
16
17
18
19
20
21
filter = SitemapFilter(
    date_range=DaysAgo(2),
    contains=r"(section1)|(section2)",
    excludes="page1",
    skip=100,
    take=50
)