Skip to main content

Python3 package for writing large XML sitemaps with no external dependencies

Project description


PyPI Downloads Coverage Status

Python3 package for writing large XML sitemaps with no external dependencies.

pip install xml-sitemap-writer


This package is meant to generate sitemaps with hundred of thousands of URLs in memory-efficient way by making use of iterators to populate sitemap with URLs.

from typing import Iterator
from xml_sitemap_writer import XMLSitemap

def get_products_for_sitemap() -> Iterator[str]:
    Replace the logic below with a query from your database.
    for idx in range(1, 1000001):
        yield f"/product/{idx}.html"  # URLs should be relative to what you provide as "root_url" below

with XMLSitemap(path='/your/web/root', root_url='') as sitemap:

sitemap.xml and sitemap-00N.xml.gz files will be generated once this code runs:

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="">
	<!-- Powered by -->
	<!-- 100000 urls -->

And gzipped sub-sitemaps with up to 15.000 URLs each:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="">
<!-- 15000 urls in the sitemap -->

For easier discovery of your sitemap add its URL to /robots.txt file:


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xml_sitemap_writer-0.5.0.tar.gz (5.0 kB view hashes)

Uploaded source

Built Distribution

xml_sitemap_writer-0.5.0-py3-none-any.whl (5.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page