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. Note that nested sitemaps up to level 2 of the index sitemaps will be included.

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 | Sequence[SearchEngineEndpoint | str]

Select the search engine you want to submit to or use a custom URL as endpoint. If a list or tuple of endpoints is given, they are tried in order until one accepts the submission. The submission falls back to the next endpoint on connection errors, server errors, 429 Too Many Requests and 403 Forbidden, but not on other client errors such as 400 Bad Request.

INDEXNOW
retries int

Number of times to retry a request on connection errors, timeouts, 429 Too Many Requests and server errors, with exponential backoff. Defaults to 0, i.e. no retries. If a list or tuple of endpoints is given, each endpoint is retried before falling back to the next one.

0

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. If a list or tuple of endpoints is given and all of them fail, the last response status is returned if any endpoint responded; otherwise, the final connection error or timeout is raised.

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_locations,
    endpoint="https://www.bing.com/indexnow")

Or provide a list of endpoints as fallback in case an endpoint is unavailable or rejects the submission. The endpoints are tried in order until one succeeds:

15
16
17
18
19
20
21
endpoints_with_fallback = [
    "https://www.bing.com/indexnow",
    "https://yandex.com/indexnow",
    "https://search.seznam.cz/indexnow",
]

submit_sitemaps_to_index_now(authentication, sitemap_locations, endpoint=endpoints_with_fallback)

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
)