> For the complete documentation index, see [llms.txt](https://infinitode-docs.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://infinitode-docs.gitbook.io/documentation/package-documentation/localsitemap-package-documentation.md).

# LocalSiteMap Package Documentation

Generate standard-compliant sitemaps and sitemap indexes from local website files.

LocalSiteMap crawls a website directory and generates standard-compliant sitemaps.

## Changelog

### 2.0.0

* Exclusions now require exact folder names or complete relative paths.
* Excluded directories are pruned during traversal.
* File timestamps use accurate UTC dates.
* `allowed_extensions` supports custom indexed file types.
* `priority_mapping` accepts a dictionary or callable.
* Large sitemaps split automatically and produce a sitemap index.

### Earlier releases

* **1.0.2**: Removed the unused `install_requires` declaration.
* **1.0.1**: Added `show_progress` progress output.
* **1.0.0**: Added recursive crawling and sitemap generation.

## Installation

Install LocalSiteMap with pip:

```bash
pip install localsitemap
```

LocalSiteMap supports Python 3.6 through 3.11 and later.

## Features

* Recursively crawls local website directories.
* Uses UTC file modification dates for `<lastmod>` metadata.
* Indexes `.html` and `.htm` files by default.
* Supports custom extensions, priority mappings, and sitemap splitting.

{% hint style="warning" %}
LocalSiteMap crawls every directory under the root. Exclude hidden, resource, and sensitive directories as needed.
{% endhint %}

## Example Usage

### Generate a basic sitemap

```python
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 are 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")
```

### Configure extensions, priorities, and splitting

```python
from localsitemap import generate_sitemap

# Use a dictionary or callable for custom priorities
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,
)
```

When URLs exceed `max_urls`, LocalSiteMap creates numbered sitemap files and a `sitemap.xml` index.

## License

LocalSiteMap uses the Modified MIT License. Substantial derivative changes must use a different name and be clearly distinguished from the original.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://infinitode-docs.gitbook.io/documentation/package-documentation/localsitemap-package-documentation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
