Werkzeug

Atom Syndication

This module provides a class called AtomFeed which can be used to generate feeds in the Atom syndication format (see RFC 4287).

Example:

def atom_feed(request):
    feed = AtomFeed("My Blog", feed_url=req.url,
                    url=req.host_url,
                    subtitle="My example blog for a feed test.")
    for post in Post.query.limit(10).all():
        feed.add(post.title, post.body, content_type='html',
                 author=post.author, url=post.url, id=post.uid,
                 updated=post.last_update, published=post.pub_date)
    return feed.get_response()
class werkzeug.contrib.atom.AtomFeed(title=None, entries=None, **kwargs)

A helper class that creates Atom feeds.

Parameters:
  • title – the title of the feed. Required.
  • title_type – the type attribute for the title element. One of 'html', 'text' or 'xhtml'.
  • url – the url for the feed (not the url of the feed)
  • id – a globally unique id for the feed. Must be an URI. If not present the feed_url is used, but one of both is required.
  • updated – the time the feed was modified the last time. Must be a datetime.datetime object. If not present the latest entry’s updated is used.
  • feed_url – the URL to the feed. Should be the URL that was requested.
  • author – the author of the feed. Must be either a string (the name) or a dict with name (required) and uri or email (both optional). Can be a list of (may be mixed, too) strings and dicts, too, if there are multiple authors. Required if not every entry has an author element.
  • icon – an icon for the feed.
  • logo – a logo for the feed.
  • rights – copyright information for the feed.
  • rights_type – the type attribute for the rights element. One of 'html', 'text' or 'xhtml'. Default is 'text'.
  • subtitle – a short description of the feed.
  • subtitle_type – the type attribute for the subtitle element. One of 'text', 'html', 'text' or 'xhtml'. Default is 'text'.
  • links – additional links. Must be a list of dictionaries with href (required) and rel, type, hreflang, title, length (all optional)
  • generator – the software that generated this feed. This must be a tuple in the form (name, url, version). If you don’t want to specify one of them, set the item to None.
  • entries – a list with the entries for the feed. Entries can also be added later with add().

For more information on the elements see http://www.atomenabled.org/developers/syndication/

Everywhere where a list is demanded, any iterable can be used.

add(*args, **kwargs)
Add a new entry to the feed. This function can either be called with a FeedEntry or some keyword and positional arguments that are forwarded to the FeedEntry constructor.
generate()
Return a generator that yields pieces of XML.
get_response()
Return a response object for the feed.
to_string()
Convert the feed into a string.
class werkzeug.contrib.atom.FeedEntry(title=None, content=None, feed_url=None, **kwargs)

Represents a single entry in a feed.

Parameters:
  • title – the title of the entry. Required.
  • title_type – the type attribute for the title element. One of 'html', 'text' or 'xhtml'.
  • content – the content of the entry.
  • content_type – the type attribute for the content element. One of 'html', 'text' or 'xhtml'.
  • summary – a summary of the entry’s content.
  • summary_type – the type attribute for the summary element. One of 'html', 'text' or 'xhtml'.
  • url – the url for the entry.
  • id – a globally unique id for the entry. Must be an URI. If not present the URL is used, but one of both is required.
  • updated – the time the entry was modified the last time. Must be a datetime.datetime object. Required.
  • author – the author of the feed. Must be either a string (the name) or a dict with name (required) and uri or email (both optional). Can be a list of (may be mixed, too) strings and dicts, too, if there are multiple authors. Required if not every entry has an author element.
  • published – the time the entry was initially published. Must be a datetime.datetime object.
  • rights – copyright information for the entry.
  • rights_type – the type attribute for the rights element. One of 'html', 'text' or 'xhtml'. Default is 'text'.
  • links – additional links. Must be a list of dictionaries with href (required) and rel, type, hreflang, title, length (all optional)
  • xml_base – The xml base (url) for this feed item. If not provided it will default to the item url.

For more information on the elements see http://www.atomenabled.org/developers/syndication/

Everywhere where a list is demanded, any iterable can be used.