### Install FastFeedParser
Source: https://github.com/kagisearch/fastfeedparser/blob/main/README.md
Use pip to install the library.
```bash
pip install fastfeedparser
```
--------------------------------
### Install FastFeedParser
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Install the base package using pip. Optional dependencies can be installed for brotli compression, advanced date parsing, or all features.
```bash
pip install fastfeedparser
```
```bash
# For brotli compression support
pip install fastfeedparser[brotli]
```
```bash
# For advanced date parsing fallback
pip install fastfeedparser[dateparser]
```
```bash
# For all optional features
pip install fastfeedparser[full]
```
--------------------------------
### Benchmark Output Example
Source: https://github.com/kagisearch/fastfeedparser/blob/main/README.md
Example output showing performance comparison between FastFeedParser and feedparser.
```text
Testing https://gessfred.xyz/rss.xml
FastFeedParser: 17 entries in 0.004s
Feedparser: 17 entries in 0.098s
Speedup: 26.3x
Testing https://fanf.dreamwidth.org/data/rss
FastFeedParser: 25 entries in 0.005s
Feedparser: 25 entries in 0.087s
Speedup: 17.9x
Testing https://jacobwsmith.xyz/feed.xml
FastFeedParser: 121 entries in 0.030s
Feedparser: 121 entries in 0.166s
Speedup: 5.5x
Testing https://bernsteinbear.com/feed.xml
FastFeedParser: 11 entries in 0.007s
Feedparser: 11 entries in 0.339s
Speedup: 50.1x
```
--------------------------------
### FastFeedParser Installation
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Instructions for installing the FastFeedParser library, including optional dependencies for enhanced functionality.
```bash
pip install fastfeedparser
# Optional dependencies for enhanced functionality:
# For brotli compression support
pip install fastfeedparser[brotli]
# For advanced date parsing fallback
pip install fastfeedparser[dateparser]
# For all optional features
pip install fastfeedparser[full]
```
--------------------------------
### Install FastFeedParser
Source: https://github.com/kagisearch/fastfeedparser/blob/main/CLAUDE.md
Installs the FastFeedParser library and its dependencies in editable mode.
```bash
pip install -e .
```
--------------------------------
### Benchmark Summary Report
Source: https://github.com/kagisearch/fastfeedparser/blob/main/README.md
Example of a full benchmark summary report.
```text
Summary:
--------------------------------------------------
Total wall-clock time: 38.70s
Successfully tested 200/200 feeds
FastFeedParser:
Total entries: 6600
Total parsing time: 0.46s
Average per feed: 0.002s
Feeds/sec: 439.0
Feedparser:
Total entries: 6555
Total parsing time: 12.31s
Average per feed: 0.062s
Feeds/sec: 16.2
Speedup: FastFeedParser is 27.0x faster
OUTLIERS: Entry Count Mismatches (2 feeds)
--------------------------------------------------
https://dylanharris.org/feed-me.rss
FastFeedParser: 35 entries
Feedparser: 0 entries
Difference: +35
https://humanwhocodes.com/feeds/all.json
FastFeedParser: 10 entries
Feedparser: 0 entries
Difference: +10
```
--------------------------------
### Initializing Date Parsing
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Initializes the library for date parsing operations.
```python
import fastfeedparser
```
--------------------------------
### FastFeedParser.parse() - Basic Usage
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Demonstrates how to use the main `parse` function to parse feeds from URLs or raw content. It supports various input formats and returns a `FastFeedParserDict`.
```python
import fastfeedparser
# Parse from URL
feed = fastfeedparser.parse('https://blog.kagi.com/rss.xml')
print(f"Feed title: {feed.feed.title}")
print(f"Feed link: {feed.feed.link}")
print(f"Number of entries: {len(feed.entries)}")
# Parse from XML string
xml_content = '''
My Blog
https://example.com
A sample RSS feedFirst Post
https://example.com/first-post
Mon, 15 Jan 2024 10:30:00 GMTThis is the first post content.john@example.comSecond Post
https://example.com/second-post
Tue, 16 Jan 2024 14:00:00 GMTThis is the second post content.'''
feed = fastfeedparser.parse(xml_content)
print(f"Title: {feed.feed.title}") # Output: My Blog
print(f"Description: {feed.feed.subtitle}") # Output: A sample RSS feed
for entry in feed.entries:
print(f"- {entry.title}: {entry.link}")
print(f" Published: {entry.published}")
print(f" Description: {entry.description[:50]}...")
```
--------------------------------
### Parsing Feeds from Bytes and Files
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Shows how to parse raw byte strings, file contents, and HTTP responses with automatic encoding detection.
```python
import fastfeedparser
# Parse UTF-8 encoded bytes
utf8_feed = b'''
UTF-8 Feed
https://example.com
Article with Unicode: \xc3\xa9\xc3\xa0\xc3\xbc
https://example.com/unicode
'''
feed = fastfeedparser.parse(utf8_feed)
print(f"Title: {feed.entries[0].title}") # "Article with Unicode: eaU"
# Reading from file
with open('feed.xml', 'rb') as f:
content = f.read()
feed = fastfeedparser.parse(content)
# From HTTP response (using requests or httpx)
import httpx
response = httpx.get('https://example.com/feed.xml')
feed = fastfeedparser.parse(response.content)
for entry in feed.entries:
print(f"- {entry.title}")
```
--------------------------------
### Benchmark Feed Parsers
Source: https://github.com/kagisearch/fastfeedparser/blob/main/CLAUDE.md
Runs benchmarks to compare the performance of FastFeedParser against the feedparser library.
```bash
python benchmark.py
```
--------------------------------
### Parse Feeds with FastFeedParser
Source: https://github.com/kagisearch/fastfeedparser/blob/main/README.md
Demonstrates parsing feeds from a URL or a string and accessing feed metadata and entries.
```python
import fastfeedparser
# Parse from URL
myfeed = fastfeedparser.parse('https://example.com/feed.xml')
# Parse from string
xml_content = '''
Example Feed
...
'''
myfeed = fastfeedparser.parse(xml_content)
# Access feed global information
print(myfeed.feed.title)
print(myfeed.feed.link)
# Access feed entries
for entry in myfeed.entries:
print(entry.title)
print(entry.link)
print(entry.published)
```
--------------------------------
### Accessing Feed Data with FastFeedParserDict
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Demonstrates attribute-style and dictionary-style access to parsed feed data, along with safe key retrieval and serialization to JSON.
```python
import fastfeedparser
feed_xml = '''
Sample Feed
https://example.com
Feed descriptionArticle Title
https://example.com/article
Mon, 15 Jan 2024 10:00:00 GMT'''
feed = fastfeedparser.parse(feed_xml)
# Attribute-style access (clean, Pythonic)
print(feed.feed.title) # "Sample Feed"
print(feed.entries[0].title) # "Article Title"
print(feed.entries[0].link) # "https://example.com/article"
# Dictionary-style access (standard Python dict operations)
print(feed['feed']['title']) # "Sample Feed"
print(feed['entries'][0]['title']) # "Article Title"
# Check for optional fields safely
entry = feed.entries[0]
author = entry.get('author', 'Unknown')
print(f"Author: {author}")
# Check if key exists
if 'media_content' in entry:
print("Has media content")
# Iterate over entry fields
for key, value in entry.items():
print(f"{key}: {value}")
# Convert to regular dict for serialization
import json
feed_dict = dict(feed)
json_output = json.dumps(feed_dict, indent=2, default=str)
print(json_output)
```
--------------------------------
### FastFeedParser.parse() - Performance Options
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Explains how to use optional boolean parameters (`include_content`, `include_tags`, `include_media`, `include_enclosures`) in the `parse` function to disable extraction of specific fields, thereby improving parsing speed when these fields are not needed.
```python
import fastfeedparser
# Fast parsing - skip content, tags, media, and enclosures
feed = fastfeedparser.parse(
'https://feeds.bbci.co.uk/news/world/rss.xml',
include_content=False, # Skip full content blobs
include_tags=False, # Skip categories/tags
include_media=False, # Skip media:content elements
include_enclosures=False # Skip RSS enclosures
)
# Access basic metadata only - faster parsing
for entry in feed.entries:
print(f"{entry.title}")
print(f" Link: {entry.link}")
print(f" Published: {entry.published}")
# Full parsing with all fields (default behavior)
feed_full = fastfeedparser.parse(
'https://feeds.bbci.co.uk/news/world/rss.xml',
include_content=True,
include_tags=True,
include_media=True,
include_enclosures=True
)
# Access all available fields
for entry in feed_full.entries:
if 'content' in entry:
print(f"Content type: {entry.content[0]['type']}")
if 'tags' in entry:
print(f"Tags: {[t['term'] for t in entry.tags]}")
if 'enclosures' in entry:
print(f"Enclosures: {entry.enclosures}")
```
--------------------------------
### Parse RDF/RSS 1.0 Feeds with Dublin Core
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Use this snippet to parse RDF/RSS 1.0 feeds, including those with Dublin Core metadata. Ensure the feed content is correctly formatted XML.
```python
import fastfeedparser
rdf_content = '''
RDF Feed Example
https://example.com
An RDF/RSS 1.0 feedAdmin2024-01-15T10:00:00ZRDF Item Title
https://example.com/item/1
Item description text.Author Name2024-01-15T10:00:00ZTechnology'''
feed = fastfeedparser.parse(rdf_content)
print(f"Feed: {feed.feed.title}")
print(f"Link: {feed.feed.link}")
print(f"Author: {feed.feed.get('author', 'N/A')}")
for entry in feed.entries:
print(f"\n{entry.title}")
print(f" ID: {entry.id}")
print(f" Link: {entry.link}")
print(f" Published: {entry.published}")
print(f" Author: {entry.get('author', 'N/A')}")
if 'tags' in entry:
print(f" Subjects: {[t['term'] for t in entry.tags]}")
```
--------------------------------
### Optimize Parsing with Performance Options
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Control the extraction of specific fields like content, tags, media, and enclosures by setting corresponding boolean parameters to `False` in the `parse` function. This can significantly speed up parsing when these fields are not required.
```python
import fastfeedparser
# Fast parsing - skip content, tags, media, and enclosures
feed = fastfeedparser.parse(
'https://feeds.bbci.co.uk/news/world/rss.xml',
include_content=False, # Skip full content blobs
include_tags=False, # Skip categories/tags
include_media=False, # Skip media:content elements
include_enclosures=False # Skip RSS enclosures
)
# Access basic metadata only - faster parsing
for entry in feed.entries:
print(f"{entry.title}")
print(f" Link: {entry.link}")
print(f" Published: {entry.published}")
```
```python
# Full parsing with all fields (default behavior)
feed_full = fastfeedparser.parse(
'https://feeds.bbci.co.uk/news/world/rss.xml',
include_content=True,
include_tags=True,
include_media=True,
include_enclosures=True
)
# Access all available fields
for entry in feed_full.entries:
if 'content' in entry:
print(f"Content type: {entry.content[0]['type']}")
if 'tags' in entry:
print(f"Tags: {[t['term'] for t in entry.tags]}")
if 'enclosures' in entry:
print(f"Enclosures: {entry.enclosures}")
```
--------------------------------
### Run All Tests
Source: https://github.com/kagisearch/fastfeedparser/blob/main/CLAUDE.md
Executes all tests within the FastFeedParser project using pytest.
```bash
pytest
```
--------------------------------
### Handle Media Content and Enclosures in RSS
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
This snippet demonstrates how to extract Media RSS (mrss) elements and RSS enclosures from feeds. It's useful for accessing podcasts, images, videos, and other media attachments along with their metadata.
```python
import fastfeedparser
rss_with_media = '''
Podcast Feed
https://example.com
Episode 1: Getting Started
https://example.com/ep1
Mon, 15 Jan 2024 10:00:00 GMTEpisode 1 VideoVideo version of episode 1Producer Name'''
feed = fastfeedparser.parse(rss_with_media)
for entry in feed.entries:
print(f"Title: {entry.title}")
# RSS Enclosures (podcasts, downloads)
if 'enclosures' in entry:
for enc in entry.enclosures:
print(f"\nEnclosure:")
print(f" URL: {enc['url']}")
print(f" Type: {enc['type']}")
print(f" Size: {enc.get('length', 'unknown')} bytes")
# Media RSS content
if 'media_content' in entry:
for media in entry.media_content:
print(f"\nMedia Content:")
print(f" URL: {media.get('url')}")
print(f" Type: {media.get('type')}")
print(f" Medium: {media.get('medium')}")
if 'width' in media and 'height' in media:
print(f" Dimensions: {media['width']}x{media['height']}")
if 'title' in media:
print(f" Title: {media['title']}")
if 'description' in media:
print(f" Description: {media['description']}")
if 'thumbnail_url' in media:
print(f" Thumbnail: {media['thumbnail_url']}")
if 'credit' in media:
print(f" Credit: {media['credit']}")
```
--------------------------------
### Benchmark FastFeedParser Only
Source: https://github.com/kagisearch/fastfeedparser/blob/main/CLAUDE.md
Runs benchmarks focusing solely on FastFeedParser's performance.
```bash
python benchmark.py -s
```
--------------------------------
### Run Specific Tests
Source: https://github.com/kagisearch/fastfeedparser/blob/main/CLAUDE.md
Runs tests that match a specific pattern, useful for targeted debugging.
```bash
pytest -k "test_name"
```
--------------------------------
### Parse RSS Feed with Various Date Formats
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Demonstrates parsing an RSS feed with different date formats. All dates are automatically normalized to UTC ISO 8601 format.
```python
feed_xml = '''
Date Examples
https://example.com
RFC 822 DateMon, 15 Jan 2024 10:30:00 GMTRFC 822 with TimezoneMon, 15 Jan 2024 05:30:00 -0500ISO 8601 with Z2024-01-15T10:30:00ZISO 8601 with Offset2024-01-15T15:30:00+05:00'''
feed = fastfeedparser.parse(feed_xml)
# All dates normalized to UTC ISO 8601 format
for entry in feed.entries:
print(f"{entry.title}")
print(f" Original -> Normalized: {entry.published}")
# All will be in format: 2024-01-15T10:30:00+00:00
```
--------------------------------
### Convert Normalized Date String to Datetime Object
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Shows how to convert the normalized ISO 8601 date string from a feed entry into a Python datetime object for further manipulation.
```python
from datetime import datetime
entry = feed.entries[0]
if entry.published:
dt = datetime.fromisoformat(entry.published)
print(f"Datetime object: {dt}")
print(f"Year: {dt.year}, Month: {dt.month}, Day: {dt.day}")
```
--------------------------------
### Parse Feed from URL or XML String
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Use the `parse` function to process feed data from a URL or a raw XML string. The function returns a `FastFeedParserDict` with attribute-style access to feed and entry data.
```python
import fastfeedparser
# Parse from URL
feed = fastfeedparser.parse('https://blog.kagi.com/rss.xml')
print(f"Feed title: {feed.feed.title}")
print(f"Feed link: {feed.feed.link}")
print(f"Number of entries: {len(feed.entries)}")
```
```python
# Parse from XML string
xml_content = '''
My Blog
https://example.com
A sample RSS feedFirst Post
https://example.com/first-post
Mon, 15 Jan 2024 10:30:00 GMTThis is the first post content.john@example.comSecond Post
https://example.com/second-post
Tue, 16 Jan 2024 14:00:00 GMTThis is the second post content.'''
feed = fastfeedparser.parse(xml_content)
print(f"Title: {feed.feed.title}") # Output: My Blog
print(f"Description: {feed.feed.subtitle}") # Output: A sample RSS feed
for entry in feed.entries:
print(f"- {entry.title}: {entry.link}")
print(f" Published: {entry.published}")
print(f" Description: {entry.description[:50]}...")
```
--------------------------------
### parse(source, ...)
Source: https://github.com/kagisearch/fastfeedparser/blob/main/README.md
The primary function used to parse feed data from a URL or raw string content.
```APIDOC
## parse(source, *, include_content=True, include_tags=True, include_media=True, include_enclosures=True)
### Description
Parses a feed from a URL, XML, or JSON source. Returns a FastFeedParserDict object containing feed metadata and entries.
### Parameters
#### Request Body
- **source** (str) - Required - The URL of the feed or the raw XML/JSON string content.
- **include_content** (bool) - Optional - Toggle for extracting full content.
- **include_tags** (bool) - Optional - Toggle for extracting categories and tags.
- **include_media** (bool) - Optional - Toggle for extracting media content.
- **include_enclosures** (bool) - Optional - Toggle for extracting file enclosures.
### Response
#### Success Response (200)
- **feed** (object) - Contains feed-level metadata (title, link, description, etc.).
- **entries** (list) - A list of entry objects containing title, link, description, published date, author, content, media_content, and enclosures.
```
--------------------------------
### Handling Parsing and Network Errors
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Provides a robust pattern for catching ValueError, HTTPError, and URLError when processing potentially invalid or unreachable feeds.
```python
import fastfeedparser
from urllib.error import HTTPError, URLError
# Handle parsing errors
def safe_parse(source):
try:
feed = fastfeedparser.parse(source)
return feed
except ValueError as e:
# Invalid XML, HTML page, empty content, etc.
print(f"Parse error: {e}")
return None
except HTTPError as e:
# HTTP errors (404, 500, etc.)
print(f"HTTP error {e.code}: {e.reason}")
return None
except URLError as e:
# Network errors
print(f"Network error: {e.reason}")
return None
except Exception as e:
# Other unexpected errors
print(f"Unexpected error: {e}")
return None
# Example with HTML page (common error)
html_content = '''
Not a feed
'''
try:
feed = fastfeedparser.parse(html_content)
except ValueError as e:
print(f"Error: {e}") # "Content appears to be HTML, not a valid RSS/Atom feed"
# Example with empty content
try:
feed = fastfeedparser.parse('')
except ValueError as e:
print(f"Error: {e}") # "Empty content"
# Process multiple feeds with error handling
urls = [
'https://valid-feed.com/rss',
'https://invalid-url.com/feed',
'https://html-page.com/'
]
feeds = []
for url in urls:
feed = safe_parse(url)
if feed:
feeds.append(feed)
print(f"Parsed {len(feed.entries)} entries from {url}")
```
--------------------------------
### Parse Atom 1.0 Feeds
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Use the parse function to extract metadata and entry details from an Atom XML string.
```python
import fastfeedparser
atom_content = '''
Example Atom Feedurn:uuid:60a76c80-d399-11d9-b93C-0003939e0af62024-01-15T18:30:02ZJane DoeAtom Entry Titleurn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a2024-01-15T18:30:02Z2024-01-15T10:00:00ZSummary of the entry content.<p>Full HTML content here.</p>John Smith'''
feed = fastfeedparser.parse(atom_content)
# Feed-level metadata
print(f"Feed ID: {feed.feed.id}")
print(f"Feed Author: {feed.feed.author}")
print(f"Feed Updated: {feed.feed.updated}")
print(f"Links: {feed.feed.links}")
# Entry-level data
for entry in feed.entries:
print(f"\nEntry: {entry.title}")
print(f" ID: {entry.id}")
print(f" Link: {entry.link}")
print(f" Published: {entry.published}")
print(f" Updated: {entry.updated}")
print(f" Author: {entry.author}")
if 'content' in entry:
print(f" Content: {entry.content[0]['value'][:50]}...")
if 'tags' in entry:
for tag in entry.tags:
print(f" Tag: {tag['term']} (scheme: {tag['scheme']})")
```
--------------------------------
### Parse JSON Feeds
Source: https://context7.com/kagisearch/fastfeedparser/llms.txt
Use the parse function to extract data from a JSON Feed string, including attachments and tags.
```python
import fastfeedparser
json_feed_content = '''{
"version": "https://jsonfeed.org/version/1.1",
"title": "My JSON Feed",
"home_page_url": "https://example.com/",
"feed_url": "https://example.com/feed.json",
"description": "A sample JSON feed",
"authors": [
{"name": "John Doe", "url": "https://example.com/johndoe"}
],
"language": "en-US",
"items": [
{
"id": "1",
"url": "https://example.com/post/1",
"title": "First JSON Feed Post",
"content_html": "
This is HTML content.
",
"summary": "A brief summary",
"date_published": "2024-01-15T10:00:00Z",
"date_modified": "2024-01-16T12:00:00Z",
"authors": [{"name": "Jane Doe"}],
"tags": ["technology", "json"],
"attachments": [
{
"url": "https://example.com/podcast.mp3",
"mime_type": "audio/mpeg",
"size_in_bytes": 12345678
}
]
}
]
}'''
feed = fastfeedparser.parse(json_feed_content)
print(f"Title: {feed.feed.title}")
print(f"Link: {feed.feed.link}")
print(f"Language: {feed.feed.language}")
print(f"Author: {feed.feed.author}")
for entry in feed.entries:
print(f"\nEntry: {entry.title}")
print(f" URL: {entry.link}")
print(f" Published: {entry.published}")
print(f" Updated: {entry.get('updated', 'N/A')}")
print(f" Author: {entry.author}")
if 'tags' in entry:
print(f" Tags: {[t['term'] for t in entry.tags]}")
if 'enclosures' in entry:
for enc in entry.enclosures:
print(f" Attachment: {enc['url']} ({enc['type']})")
if 'content' in entry:
print(f" Content type: {entry.content[0]['type']}")
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.