Python3 package for writing large XML sitemaps with no external dependencies
Project description
py-xml-sitemap-writer
Python3 package for writing large XML sitemaps with no external dependencies.
pip install xml-sitemap-writer
Usage
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='https://your.site.io') as sitemap:
sitemap.add_section('products')
sitemap.add_urls(get_products_for_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="http://www.sitemaps.org/schemas/sitemap/0.9">
<!-- Powered by https://github.com/pigs-will-fly/py-xml-sitemap-writer -->
<!-- 100000 urls -->
<sitemap><loc>https://your.site.io/sitemap-products-001.xml.gz</loc></sitemap>
<sitemap><loc>https://your.site.io/sitemap-products-002.xml.gz</loc></sitemap>
...
</sitemapindex>
And gzipped sub-sitemaps with up to 15.000 URLs each:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>https://your.site.io/product/1.html</loc></url>
<url><loc>https://your.site.io/product/2.html</loc></url>
<url><loc>https://your.site.io/product/3.html</loc></url>
...
</urlset>
<!-- 15000 urls in the sitemap -->
For easier discovery of your sitemap add its URL to /robots.txt file:
Sitemap: https://your.site.io/sitemap.xml
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xml_sitemap_writer-0.7.0.tar.gz.
File metadata
- Download URL: xml_sitemap_writer-0.7.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5a1b6442d9fae578e11b02f4d0a09961e1765741dca128bf92cebc1be653ea4
|
|
| MD5 |
3c77650b3932ebdb3a4e5306bffdf534
|
|
| BLAKE2b-256 |
e5f2174255402195cc6a2d86a1428c91b291d69d3eaa976c248e8b3748f7fb73
|
Provenance
The following attestation bundles were made for xml_sitemap_writer-0.7.0.tar.gz:
Publisher:
python-publish.yml on pigs-will-fly/py-xml-sitemap-writer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xml_sitemap_writer-0.7.0.tar.gz -
Subject digest:
c5a1b6442d9fae578e11b02f4d0a09961e1765741dca128bf92cebc1be653ea4 - Sigstore transparency entry: 612051883
- Sigstore integration time:
-
Permalink:
pigs-will-fly/py-xml-sitemap-writer@f0eb9e8db14f0c9a97b60ac1090cca790e8ccb1c -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/pigs-will-fly
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f0eb9e8db14f0c9a97b60ac1090cca790e8ccb1c -
Trigger Event:
release
-
Statement type:
File details
Details for the file xml_sitemap_writer-0.7.0-py3-none-any.whl.
File metadata
- Download URL: xml_sitemap_writer-0.7.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e3f1ce3562f10fb61b7d4b11cc8f939b4463861be0c038401c390a4506d9c63
|
|
| MD5 |
bb9238ff9c74a864954bf03436891b80
|
|
| BLAKE2b-256 |
533cccef414679becf7d90faca5566f6989920bbc32f515caf87dee1a1a0d025
|
Provenance
The following attestation bundles were made for xml_sitemap_writer-0.7.0-py3-none-any.whl:
Publisher:
python-publish.yml on pigs-will-fly/py-xml-sitemap-writer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xml_sitemap_writer-0.7.0-py3-none-any.whl -
Subject digest:
0e3f1ce3562f10fb61b7d4b11cc8f939b4463861be0c038401c390a4506d9c63 - Sigstore transparency entry: 612051885
- Sigstore integration time:
-
Permalink:
pigs-will-fly/py-xml-sitemap-writer@f0eb9e8db14f0c9a97b60ac1090cca790e8ccb1c -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/pigs-will-fly
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f0eb9e8db14f0c9a97b60ac1090cca790e8ccb1c -
Trigger Event:
release
-
Statement type: