Skip to main content

Flask extension for generating XML sitemaps

Project description

Flask Sitemapper

GitHub Workflow Status PyPI - Downloads

Flask Sitemapper is a Python 3 package that generates XML sitemaps for Flask applications. This allows you to create fully functional sitemaps and sitemap indexes for your Flask projects with minimal code.

You can install the latest version of Flask Sitemapper with pip:

pip install flask-sitemapper

For documentation (including for contributors), see the wiki.

Features

  • Easily generate and serve XML sitemaps and sitemap indexes for your Flask apps
  • Include URLs in your sitemaps by adding a decorator to their route/view functions
  • Serve your sitemap on any URL you choose
  • Include lastmod, changefreq, and priority information in your sitemaps
  • Specify whether to use HTTP or HTTPS for the URLs in your sitemaps
  • Compress your sitemaps using GZIP
  • Create multiple sitemaps and sitemap indexes for the same app
  • Supports apps using Flask blueprints
  • Supports apps serving multiple domains
  • Works with many different app structures

Sitemaps

Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling. In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL (when it was last updated, how often it usually changes, and how important it is, relative to other URLs in the site) so that search engines can more intelligently crawl the site. — sitemaps.org

For more information about sitemaps and the sitemap protocol, visit sitemaps.org

Basic Code Example

import flask
from flask_sitemapper import Sitemapper

sitemapper = Sitemapper()

app = flask.Flask(__name__)
sitemapper.init_app(app)

@sitemapper.include(lastmod="2022-02-08")
@app.route("/")
def home():
  return flask.render_template("home.html")

@sitemapper.include(lastmod="2022-03-19")
@app.route("/about")
def about():
  return flask.render_template("about.html")

@app.route("/sitemap.xml")
def sitemap():
  return sitemapper.generate()

app.run()

With the above code running on localhost, http://localhost/sitemap.xml will serve the following XML sitemap:

<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://localhost/</loc>
    <lastmod>2022-02-08</lastmod>
  </url>
  <url>
    <loc>https://localhost/about</loc>
    <lastmod>2022-03-19</lastmod>
  </url>
</urlset>

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

flask_sitemapper-1.5.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

flask_sitemapper-1.5.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file flask_sitemapper-1.5.1.tar.gz.

File metadata

  • Download URL: flask_sitemapper-1.5.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for flask_sitemapper-1.5.1.tar.gz
Algorithm Hash digest
SHA256 2ca9db7273957953b8dbd7d0c238f9c2d92338249197ecf4f5736dbe7bc33ee9
MD5 0506f960bed0fd1e684f034444f90cd4
BLAKE2b-256 20c6c6806d892e65898eba8304d2d1b144fb3a51d77340d715c62d8ea5727db4

See more details on using hashes here.

File details

Details for the file flask_sitemapper-1.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_sitemapper-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c223de121c724bc4495c8b61ceafd90b32d37d94a9ae3c00c4665f10e5a85a74
MD5 9fc9c7686c216c009e770ebe7481103f
BLAKE2b-256 47e39f8a0f61346a69f804d0f3435dcc5eab41a27d4f2dcf29b716a94c2a637b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page