Feed Generator (ATOM, RSS, Podcasts)

1.0.0 · active · verified Thu Apr 16

feedgen is a Python library (version 1.0.0) for generating web feeds in ATOM and RSS formats, including support for podcast extensions. It is a standalone evolution of Django's `feedgenerator` module, licensed under both FreeBSD and LGPLv3+. The library maintains an active development status, with its latest stable release on December 25, 2023, and continues to be a robust tool for programmatic feed creation.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic RSS feed (and optionally ATOM) with a few entries using `FeedGenerator`. It includes setting global feed properties like ID, title, author, and links, and then adding individual entries with their own metadata. Date fields are set with timezone information, which is crucial for proper feed parsing. Finally, it shows how to generate the feed as a pretty-printed string.

from feedgen.feed import FeedGenerator
import datetime

fg = FeedGenerator()
fg.id('http://example.com/pages/1')
fg.title('My Example Feed')
fg.author({'name': 'John Doe', 'email': 'john.doe@example.com'})
fg.link(href='http://example.com', rel='alternate')
fg.link(href='http://example.com/feed.xml', rel='self')
fg.language('en')
fg.description('A fantastic example feed generated by feedgen.')
fg.lastBuildDate(datetime.datetime.now(datetime.timezone.utc))

# Add an entry
fe = fg.add_entry()
fe.id('http://example.com/pages/1/article1')
fe.title('First Article Title')
fe.link(href='http://example.com/articles/1')
fe.published(datetime.datetime(2023, 1, 10, 10, 0, 0, tzinfo=datetime.timezone.utc))
fe.updated(datetime.datetime(2023, 1, 15, 12, 30, 0, tzinfo=datetime.timezone.utc))
fe.summary('This is a summary of the first article.')
fe.content('This is the full content of the first article, potentially with <b>HTML</b>.')
fe.author({'name': 'Jane Doe', 'email': 'jane.doe@example.com'})

# Add another entry
fe2 = fg.add_entry()
fe2.id('http://example.com/pages/1/article2')
fe2.title('Second Article Title')
fe2.link(href='http://example.com/articles/2')
fe2.published(datetime.datetime(2023, 2, 1, 9, 0, 0, tzinfo=datetime.timezone.utc))
fe2.updated(datetime.datetime(2023, 2, 5, 11, 45, 0, tzinfo=datetime.timezone.utc))
fe2.summary('Summary of the second article.')

# Generate and print the RSS feed
print(fg.rss_str(pretty=True).decode('utf-8'))

# Generate and print the ATOM feed
# print(fg.atom_str(pretty=True).decode('utf-8'))

view raw JSON →