PyRSS2Gen-0.0 - an RSS 2.0 generator for Python

Andrew Dalke
Sun, 07 Sep 2003 09:19:22 GMT

PyRSS2Gen - an RSS 2.0 generator for Python

I've finally decided to catch up with 1999 and play around a bit with RSS.
I looked around, and while there are many ways to read RSS there are
remarkably few which write them. I could use a DOM or other
construct, but I want the code to feel like Python. There are more Pythonic
APIs I might use, like the effbot's ElementTree, but I also wanted integers,
dates, and lists to be real integers, dates, and lists.

The RSS generators I found were built around print statements. Workable,
but they almost invariably left out proper HTML escaping the sort which
leads to Mark Pilgrim's to write feed_parser, to make sense of
documents which are neither XML nor HTML. Annoying, but sadly
all too common.   Those which were more correct (like didn't
support all the options in an RSS feed.

This version uses native Python classes, with (untested) support for
developing your own RSS extensions.  It generates the output using
the standard SAX2 content handlers, so everything must be appropriately
escaped.  And it like Python data types, including datetime.

Here's what it looks like:

import datetime
import PyRSS2Gen

rss = PyRSS2Gen.RSS2(
    title = "Andrew's PyRSS2Gen feed",
    link = "",
    description = "The latest news about PyRSS2Gen, a "
                  "Python library for generating RSS2 feeds",

    lastBuildDate =,

    items = [
         title = "PyRSS2Gen-0.0 released",
         link = "",
         description = "Dalke Scientific today announced PyRSS2Gen-0.0, "
                       "a library for generating RSS feeds for Python.  ",
         guid = PyRSS2Gen.Guid(""
         pubDate = datetime.datetime(2003, 9, 6, 21, 31)),
         title = "Thoughts on RSS feeds for bioinformatics",
         link = ""
         description = "One of the reasons I wrote PyRSS2Gen was to "
                       "experiment with RSS for data collection in "
                       "bioinformatics.  Last year I came across...",
         guid = PyRSS2Gen.Guid(""
         pubDate = datetime.datetime(2003, 9, 6, 21, 49)),

rss.write_xml(open("pyrss2gen.xml", "w"))

And amazingly enough, it actually validated on the first try!

PyRSS2Gen is released under the BSD license.