feedparser-rs
v0.3.0
Published
High-performance RSS/Atom/JSON Feed parser for Node.js
Maintainers
Readme
feedparser-rs
High-performance RSS/Atom/JSON Feed parser for Node.js, written in Rust.
Drop-in replacement for Python's feedparser library, offering 10-100x performance improvement.
Features
- Fast: Written in Rust, 10-100x faster than Python feedparser
- Tolerant: Handles malformed feeds with bozo flag (like feedparser)
- Multi-format: RSS 0.9x/1.0/2.0, Atom 0.3/1.0, JSON Feed 1.0/1.1
- HTTP fetching: Built-in URL fetching with compression support
- TypeScript: Full TypeScript definitions included
- Zero-copy: Efficient parsing with minimal allocations
Installation
npm install feedparser-rs
# or
yarn add feedparser-rs
# or
pnpm add feedparser-rs[!IMPORTANT] Requires Node.js 18 or later.
Quick Start
import { parse } from 'feedparser-rs';
const feed = parse(`
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>My Blog</title>
<item>
<title>Hello World</title>
<link>https://example.com/1</link>
</item>
</channel>
</rss>
`);
console.log(feed.feed.title); // "My Blog"
console.log(feed.entries[0].title); // "Hello World"
console.log(feed.version); // "rss20"HTTP Fetching
Fetch and parse feeds directly from URLs:
import { fetchAndParse } from 'feedparser-rs';
const feed = await fetchAndParse('https://example.com/feed.xml');
console.log(feed.feed.title);
console.log(`Fetched ${feed.entries.length} entries`);[!TIP]
fetchAndParseautomatically handles compression (gzip, deflate, brotli) and follows redirects.
Parsing from Buffer
import { parse } from 'feedparser-rs';
const response = await fetch('https://example.com/feed.xml');
const buffer = Buffer.from(await response.arrayBuffer());
const feed = parse(buffer);API
parse(source: Buffer | string | Uint8Array): ParsedFeed
Parse a feed from bytes or string.
Parameters:
source- Feed content as Buffer, string, or Uint8Array
Returns:
ParsedFeedobject with feed metadata and entries
Throws:
Errorif parsing fails catastrophically
fetchAndParse(url: string): Promise<ParsedFeed>
Fetch and parse a feed from URL.
Parameters:
url- Feed URL to fetch
Returns:
- Promise resolving to
ParsedFeedobject
detectFormat(source: Buffer | string | Uint8Array): string
Detect feed format without full parsing.
Returns:
- Format string:
"rss20","atom10","json11", etc.
const format = detectFormat('<feed xmlns="http://www.w3.org/2005/Atom">...</feed>');
console.log(format); // "atom10"Types
ParsedFeed
interface ParsedFeed {
feed: FeedMeta;
entries: Entry[];
bozo: boolean;
bozo_exception?: string;
encoding: string;
version: string;
namespaces: Record<string, string>;
}FeedMeta
interface FeedMeta {
title?: string;
title_detail?: TextConstruct;
link?: string;
links: Link[];
subtitle?: string;
updated?: number; // Milliseconds since epoch
author?: string;
authors: Person[];
language?: string;
image?: Image;
tags: Tag[];
id?: string;
ttl?: number;
}Entry
interface Entry {
id?: string;
title?: string;
link?: string;
links: Link[];
summary?: string;
content: Content[];
published?: number; // Milliseconds since epoch
updated?: number;
author?: string;
authors: Person[];
tags: Tag[];
enclosures: Enclosure[];
}[!NOTE] See
index.d.tsfor complete type definitions includingLink,Person,Tag,Image,Enclosure, and more.
Error Handling
The library uses a "bozo" flag (like feedparser) to indicate parsing errors while still returning partial results:
const feed = parse('<rss><channel><title>Broken</title></rss>');
if (feed.bozo) {
console.warn('Feed has errors:', feed.bozo_exception);
}
// Still can access parsed data
console.log(feed.feed.title); // "Broken"Dates
All date fields are returned as milliseconds since Unix epoch. Convert to JavaScript Date:
const entry = feed.entries[0];
if (entry.published) {
const date = new Date(entry.published);
console.log(date.toISOString());
}Performance
Benchmarks on Apple M1 Pro:
| Feed Size | Time | Throughput | |-----------|------|------------| | Small (2 KB) | 0.01 ms | 187 MB/s | | Medium (20 KB) | 0.09 ms | 214 MB/s | | Large (200 KB) | 0.94 ms | 213 MB/s |
vs Python feedparser
| Operation | feedparser-rs | Python feedparser | Speedup | |-----------|---------------|-------------------|---------| | Parse 20 KB RSS | 0.09 ms | 8.5 ms | 94x | | Parse 200 KB RSS | 0.94 ms | 85 ms | 90x |
[!TIP] For best performance, pass
Bufferinstead ofstringto avoid UTF-8 conversion overhead.
Platform Support
Pre-built binaries available for:
| Platform | Architecture | |----------|--------------| | macOS | Intel (x64), Apple Silicon (arm64) | | Linux | x64, arm64 | | Windows | x64 |
Supported Node.js versions: 18, 20, 22+
Development
# Install dependencies
npm install
# Build native module
npm run build
# Run tests
npm test
# Run tests with coverage
npm run test:coverageLicense
Licensed under either of:
at your option.
