Skip to main content

LocalSiteMap

Python Version Code Size Downloads License Compliance PyPI Version

LocalSiteMap is an open-source Python package designed for generating sitemaps and sitemap indexes from local files. It crawls your root website directory and automatically builds standard-compliant sitemaps.

Changes in version 2.0.0 (Major Release):

  • Precise Exclusions: Rewrote exclusion matching so only exact folder or filename matches (not partial substring matches) are excluded.
  • Traversal Optimization: Subdirectories matching the exclusion list are pruned in-place, eliminating the overhead of traversing skipped directories.
  • UTC Timestamps: Fixed timezone bug to retrieve and format all file modification timestamps as true, accurate UTC standard dates.
  • Customizable File Extensions: Added optional allowed_extensions parameter to let you specify any list of file types to index (defaults to [".html", ".htm"]).
  • Flexible Priority Mappings: Custom mapping for directory/page priorities using a dictionary or callable mapping function.
  • Sitemap Splitting & Sitemap Indexing: Automatically splits large sitemaps into chunks and creates a standard <sitemapindex> parent if the URL limit (max_urls, defaults to 50,000) is exceeded.

Changes in version 1.0.2:

  • Removed the unnecessary install_requires from the setup.py as the package utilizes none of the required packages.

Changes in version 1.0.1:

  • Added show_progress boolean to print out mapping progress, pages mapped, and files found.

Changes in version 1.0.0:

  • Added initial package code, with automatic directory crawling to generate the sitemap.xml file.

[!IMPORTANT] LocalSiteMap crawls any directory found in the root folder, be sure to add exclusions for important directories, or hidden/resource/file directories.

Installation

You can install LocalSiteMap using pip:

pip install localsitemap

Supported Python Versions

LocalSiteMap supports the following Python versions:

  • Python 3.6
  • Python 3.7
  • Python 3.8
  • Python 3.9
  • Python 3.10
  • Python 3.11/Later (Preferred)

Features

  • Directory Crawling: LocalSiteMap automatically crawls all subdirectories and files under the root directory, recursively adding them to your sitemap.
  • Optimized Walking: Excluded directories are completely skipped during traversal to ensure high performance even for large projects.
  • UTC Last Modified Checks: Accurate file modification UTC timezone checks automatically update the <lastmod> metadata tag.
  • Sitemap Splitting & Indexes: Automatically partitions large lists of pages/folders into multiple numbered sitemaps (e.g. sitemap_1.xml, sitemap_2.xml) and outputs a compliant sitemap.xml index.
  • Customizable Extensions: Configure any extensions you want mapped instead of just standard HTML (e.g. php, pdf, txt).
  • Flexible Priority Mapping: Map explicit paths to customized page weightings via custom definitions or callable filters.
  • Open Source: Released under the terms of the Modified MIT License.

Usage

Generating a basic sitemap

from localsitemap import generate_sitemap

# Root site directory
root_directory = r"path/to/your/website/directory"

# Domain of your website (where it is hosted)
base_url_of_your_website = "https://example.com"

# Only exact folder names or complete relative paths will be skipped
excluded = ["auth", "forms", "template.html", "media", ".git", ".vscode", "node_modules"]

# Generate the sitemap
generate_sitemap(root_directory, base_url_of_your_website, "sitemap.xml", excluded, show_progress=True)
print("Sitemap generated in sitemap.xml")

Advanced Features (Extensions, Mappings & Splitting)

from localsitemap import generate_sitemap

# Custom priority dictionary or callable mapper
priority_mapping = {
    "about/index.html": 0.95,
    "blog/": 0.70,
    ".php": 0.50
}

generate_sitemap(
    root_path=r"path/to/website",
    base_url="https://example.com",
    output_file="sitemap.xml",
    excluded_paths=["node_modules", ".git"],
    allowed_extensions=[".html", ".htm", ".php"],
    default_priority=0.80,
    homepage_priority=1.00,
    priority_mapping=priority_mapping,
    max_urls=1000  # Will automatically split and output a sitemap index if URLs exceed 1000
)

Contributing

Contributions are welcome! If you encounter any issues, have suggestions, or want to contribute to LocalSiteMap, please open an issue or submit a pull request on GitHub.

License

LocalSiteMap is released under the terms of the MIT License (Modified). Please see the LICENSE file for the full text.

Modified License Clause

The modified license clause grants users the permission to make derivative works based on the LocalSiteMap software. However, it requires any substantial changes to the software to be clearly distinguished from the original work and distributed under a different name.

Download files

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

Source Distribution

localsitemap-2.0.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

localsitemap-2.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file localsitemap-2.0.0.tar.gz.

File metadata

  • Download URL: localsitemap-2.0.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for localsitemap-2.0.0.tar.gz
Algorithm Hash digest
SHA256 b64a1db41731c042745498fd37c974a686516f9dd5cf3b1070ec42dd5f43300e
MD5 f07a4425ec1706fa7bc7f644be9809bc
BLAKE2b-256 7d4855b5d503629b8131ffeffb5c2edcc9d310a19b578146004328e286a579af

See more details on using hashes here.

File details

Details for the file localsitemap-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: localsitemap-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for localsitemap-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94cc5cb3b89ef0290d911b1815ac0b138d5383b901054a145c7f55f9eaa7a73d
MD5 065cbf5f3253d3e0b750feefe153e94c
BLAKE2b-256 1a454e77ba2c095752ccc1e35fe85fff7aac9e9b8e3d0431f4c35c0e80706bef

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page