Registry / serialization / feedgen

feedgen

JSON →
library1.0.0pypypi✓ verified 86d ago

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.

pip install feedgen
INSTALL
IMPORT
SIG · FEEDGEN
F
feedgen
serializationpythonv1.0.0
Install
3.2s avg
Import
80ms
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.083s · 32.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.2s · import 0.077s · 33MB
30MB installed
● package 30MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FeedGenerator
from feedgen.feed import FeedGenerator
FeedEntry
from feedgen.entry import FeedEntry

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'))
Debug
Known issues
breakingVersion 1.0.0 removed official support for Python 2. While older versions might work, Python 2 is no longer tested or maintained.
fix
Ensure your project runs on Python 3.x. Upgrade your Python environment if necessary.
affects: 1.0.0+
gotchaDate and time fields (`pubDate`, `lastBuildDate`, `published`, `updated`) *must* include timezone information for proper parsing by feed readers. Without it, readers may incorrectly interpret dates (e.g., as future dates) or repeatedly fetch content.
fix
Always provide timezone-aware datetime objects, e.g., `datetime.datetime.now(datetime.timezone.utc)` or use `dateutil.parser.parse('2023-01-01T12:00:00+00:00')`.
affects: all
gotchaRSS feeds require a `guid` (Global Unique Identifier) for each entry to uniquely identify it. While `feedgen` provides a `guid()` method, ensure the value is truly unique and consistent for the item across feed updates. For items that are not permalinks, set `isPermaLink=False`.
fix
Use `fe.guid('your-unique-id-string', isPermaLink=False)` if the ID is not a permanent URL to the item. The ID should be unique to the content, not necessarily the URL.
affects: all
gotchaImproperly formatted XML can lead to feed validation errors or prevent feed readers from parsing your content. This often happens with special characters in content or missing required fields.
fix
Always use `feedgen`'s methods for setting content (`fe.content()`, `fe.summary()`) which handle escaping. Validate your generated feed using online validators (e.g., W3C Feed Validator).
affects: all
Errors
Common errors & fixes
ValueError: unconverted data remains: ' GMT'
Attempting to set a date string that `dateutil.parser` (used internally by feedgen) cannot fully parse, often due to non-standard format or trailing text.
fix
Ensure date strings are in a standard format (e.g., ISO 8601) and include timezone information, or pass a `datetime.datetime` object with `tzinfo` set.
XML Syntax Error: Entity '...' not defined
Special characters like `&`, `<`, `>` are not properly escaped in the feed content, violating XML rules.
fix
Let `feedgen` handle content by passing plain strings to `fe.content()` or `fe.fe.summary()`. It will automatically escape these characters. Avoid manually constructing XML snippets within content fields.
Feed reader shows old items or fetches repeatedly.
This usually indicates missing or incorrect `pubDate`/`lastBuildDate` with timezone information, leading the reader to believe content is new or its update status is ambiguous.
fix
Verify that `fg.lastBuildDate()` and `fe.published()`/`fe.updated()` are always set with timezone-aware `datetime` objects, preferably UTC, e.g., `datetime.datetime.now(datetime.timezone.utc)`.
Upgrade
Version history
1.0.0latest on PyPI · released Dec 25, 2023
Audit
Dependencies
python-dateutilrequiredRequired for parsing and handling date/time information in feeds, especially for timezone awareness.
lxmlrequiredUsed for efficient XML generation and manipulation, forming the core of the feed output.
Agent activity
8 hits · last 30 days
node
6
Resources