Skip to main content
Quarantined

This project has been quarantined by PyPI admins. It cannot be installed or modified until a security review is complete.

Starlette FeedGen

Asynchronous RSS/Atom feeds generation for Starlette, adapted from Django syndication feed framework.

Note that in version 0.1.4 and higher we support only Python 3.10+ and all library classes now provide asynchronous methods. If any of these does not meet your needs please consider using version 0.1.3 of the library.

Installation

pip install starlette-feedgen

Usage

Here's a simple example of handling route /feed using FeedEndpoint class.

from typing import NamedTuple
from starlette.applications import Starlette
from starlette_feedgen import FeedEndpoint


class FeedItem(NamedTuple):
    title = 'Hello'
    description = 'There'
    link = 'http://example.com/article'

    
app = Starlette()


@app.route('/feed')
class Feed(FeedEndpoint):
    title = 'Example RSS Feed'
    description = 'With example item'
    link = 'http://example.com'

    async def get_items(self):

        def item_generator():
            yield FeedItem()

        return item_generator()

Example RSS Output:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Example RSS Feed</title>
        <link>http://example.com</link>
        <description>With example item</description>
        <atom:link rel="self" href="/feed"></atom:link>
        <lastBuildDate>Thu, 20 Oct 2022 12:46:17 +0000</lastBuildDate>
        <item>
            <title>Hello</title>
            <link>http://example.com/article</link>
            <description>There</description>
            <guid>http://example.com/article</guid>
        </item>
    </channel>
</rss>

Note that FeedEndpoint creates a feed generator object Rss201rev2Feed under the hood. You can explicitly import a feed generator class and work with it, for example:

import aiofiles
import asyncio
from starlette_feedgen.generator import Rss201rev2Feed

feed = Rss201rev2Feed(
    title='Poynter E-Media Tidbits',
    link='http://www.poynter.org/column.asp?id=31',
    description='A group Weblog by the sharpest minds in online media/journalism/publishing.',
    language='en',
)

feed.add_item(
    title='Hello',
    link='http://www.holovaty.com/test/',
    description='Testing.'
)


async def write_to_file():
    async with aiofiles.open('test.rss', 'w') as f:
        await feed.write(f, 'utf-8')

asyncio.run(write_to_file())

RSS Output:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Poynter E-Media Tidbits</title>
		<link>http://www.poynter.org/column.asp?id=31</link>
		<description>A group Weblog by the sharpest minds in online media/journalism/publishing.</description>
		<language>en</language>
		<lastBuildDate>Thu, 20 Oct 2022 13:24:50 +0000</lastBuildDate>
		<item>
			<title>Hello</title>
			<link>http://www.holovaty.com/test/</link>
			<description>Testing.</description>
		</item>
	</channel>
</rss>

For definitions of the different versions of RSS, see: https://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004/02/04/incompatible-rss

Metadata

Release files for starlette-feedgen 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for starlette-feedgen 0.1.4
File Size Uploaded
starlette_feedgen-0.1.4.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for starlette-feedgen 0.1.4
File Interpreter ABI Platform
starlette_feedgen-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 25.5 kB

Release files / starlette_feedgen-0.1.4.tar.gz

Download URL starlette_feedgen-0.1.4.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4e6eec985629b1bb1b6e9a7c006c762425754a67e379a485f7ad08d4c751e2a5
BLAKE2b-256 checksum
How to use checksums
36a43d7fafc98402cdadaa0da978a3804ba17f28d039d65de98c22f857a77f4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.10.8 Darwin/21.6.0

Release files / starlette_feedgen-0.1.4-py3-none-any.whl

Download URL starlette_feedgen-0.1.4-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a071d6ffbf5e567420073a21f8b69d9fa7bc4843e15b12f847cdc2569d5ee7cd
BLAKE2b-256 checksum
How to use checksums
10c0458fb7889c05cf55e60c5b4262320d48ed10d99242db8fb74555cb76fe61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.10.8 Darwin/21.6.0
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page