Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Dynamic sitemap

Python version Build Status codecov PyPI - Downloads

The simple sitemap generator for Python projects.

Installation

  • using pip
pip install dynamic-sitemap

Usage

Static

from datetime import datetime
from dynamic_sitemap import SimpleSitemap, ChangeFreq

urls = [
    '/',
    {'loc': '/contacts', 'changefreq': ChangeFreq.NEVER.value},
    {'loc': '/about', 'priority': 0.9, 'lastmod': datetime.now().isoformat()},
]
sitemap = SimpleSitemap('https://mysite.com', urls)
# or sitemap.render()
sitemap.write('static/sitemap.xml')

Dynamic

Only FlaskSitemap is implemented yet, so there is an example:

from dynamic_sitemap import FlaskSitemap
from flask import Flask

app = Flask(__name__)
sitemap = FlaskSitemap(app, 'https://mysite.com')
sitemap.build()

Then run your server and visit http://mysite.com/sitemap.xml.

The basic example with some Models:

from dynamic_sitemap import ChangeFreq, FlaskSitemap
from flask import Flask
from models import Post, Tag

app = Flask(__name__)
sitemap = FlaskSitemap(app, 'https://mysite.com', orm='sqlalchemy')
sitemap.config.TIMEZONE = 'Europe/Moscow'
sitemap.ignore('/edit', '/upload')
sitemap.add_items(
    '/contacts',
    {'loc': '/faq', 'changefreq': ChangeFreq.MONTHLY.value, 'priority': 0.4},
)
sitemap.add_rule('/blog', Post, loc_from='slug', priority=1.0)
sitemap.add_rule('/blog/tag', Tag, loc_from='id', changefreq='daily')
sitemap.build()

Also you can set configurations from your class (and it's preferred):

from dynamic_sitemap import ChangeFreq, FlaskSitemap
from flask import Flask
from models import Product

class Config:
    FILENAME = 'static/sitemap.xml'
    IGNORED = {'/admin', '/back-office', '/other-pages'}
    ALTER_PRIORITY = 0.1

app = Flask(__name__)
sitemap = FlaskSitemap(app, 'https://myshop.org', config=Config)
sitemap.add_items(
    '/contacts',
    {'loc': '/about', 'changefreq': ChangeFreq.MONTHLY.value, 'priority': 0.4},
)
sitemap.add_rule('/goods', Product, loc_from='id', lastmod_from='updated')
sitemap.build()

Not supported yet:

  • urls with more than 1 converter, such as /page/<int:user_id>/<str:slug>

Check out the Changelog.

Contributing

Feel free to suggest any improvements :)

Development

Fork this repository, clone it and install dependencies:

pip install -r requirements/all.txt 

Checkout to a new branch, add your feature and some tests, then try:

make precommit

If the result is ok, create a pull request to "dev" branch of this repo with a detailed description.
Done!

Metadata

Release files for dynamic-sitemap 1.0.0a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dynamic-sitemap 1.0.0a1
File Size Uploaded
dynamic-sitemap-1.0.0a1.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dynamic-sitemap 1.0.0a1
File Interpreter ABI Platform
dynamic_sitemap-1.0.0a1-py3-none-any.whl Python 3 none any Details

Total release size: 27.3 kB

Release files / dynamic-sitemap-1.0.0a1.tar.gz

Download URL dynamic-sitemap-1.0.0a1.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1c5a2135c12abd996ac7c783a652b41da505b0829ae38385959519b142e86c73
BLAKE2b-256 checksum
How to use checksums
8fa9eafd84da5cebfe879c9a8878b89cc373aa6cbd582f009dd8b78e5bc8e0fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.5.0 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.10

Release files / dynamic_sitemap-1.0.0a1-py3-none-any.whl

Download URL dynamic_sitemap-1.0.0a1-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eefab86b43d8afd005cd11089a338a380555a6913c011fe2a704670664724949
BLAKE2b-256 checksum
How to use checksums
904cc4616afd78d2c8c320b94f6a3cdc117411940528d24257b5eb90d774abbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.5.0 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.10
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