Python library for generating web feeds in both ATOM and RSS formats with extensible support for specialized feed formats
—
Core functionality for creating FeedGenerator instances and generating ATOM and RSS feed output in various formats.
The main class for creating and configuring web feeds.
class FeedGenerator:
def __init__(self):
"""
Create a new FeedGenerator instance.
Initializes empty feed with default generator metadata.
"""Generate ATOM 1.0 format feeds as strings or files.
def atom_str(self, pretty=False, extensions=True, encoding='UTF-8', xml_declaration=True):
"""
Generate ATOM feed as string.
Args:
pretty (bool): Pretty print XML with indentation
extensions (bool): Include loaded extensions in output
encoding (str): Character encoding for output
xml_declaration (bool): Include XML declaration in output
Returns:
bytes: ATOM feed XML as encoded bytes
"""
def atom_file(self, filename, extensions=True, pretty=False, encoding='UTF-8', xml_declaration=True):
"""
Write ATOM feed to file.
Args:
filename (str): Output file path
extensions (bool): Include loaded extensions in output
pretty (bool): Pretty print XML with indentation
encoding (str): Character encoding for output
xml_declaration (bool): Include XML declaration in output
Returns:
str: The filename that was written
"""Generate RSS 2.0 format feeds as strings or files.
def rss_str(self, pretty=False, extensions=True, encoding='UTF-8', xml_declaration=True):
"""
Generate RSS feed as string.
Args:
pretty (bool): Pretty print XML with indentation
extensions (bool): Include loaded extensions in output
encoding (str): Character encoding for output
xml_declaration (bool): Include XML declaration in output
Returns:
bytes: RSS feed XML as encoded bytes
"""
def rss_file(self, filename, extensions=True, pretty=False, encoding='UTF-8', xml_declaration=True):
"""
Write RSS feed to file.
Args:
filename (str): Output file path
extensions (bool): Include loaded extensions in output
pretty (bool): Pretty print XML with indentation
encoding (str): Character encoding for output
xml_declaration (bool): Include XML declaration in output
Returns:
str: The filename that was written
"""from feedgen.feed import FeedGenerator
fg = FeedGenerator()
fg.id('http://example.com/feed')
fg.title('My Feed')
fg.author({'name': 'Author Name', 'email': 'author@example.com'})
fg.link(href='http://example.com', rel='alternate')
fg.description('Feed description')
fg.language('en')
# Generate pretty-printed ATOM feed
atom_feed = fg.atom_str(pretty=True)
print(atom_feed.decode('utf-8'))
# Generate RSS feed
rss_feed = fg.rss_str(pretty=True)
print(rss_feed.decode('utf-8'))# Write feeds to files
fg.atom_file('output.atom', pretty=True)
fg.rss_file('output.rss', pretty=True)
# Generate without extensions
atom_no_ext = fg.atom_str(extensions=False)
rss_no_ext = fg.rss_str(extensions=False)# Generate with different encoding
atom_utf16 = fg.atom_str(encoding='UTF-16', pretty=True)
fg.atom_file('feed_utf16.atom', encoding='UTF-16')Install with Tessl CLI
npx tessl i tessl/pypi-feedgen