Skip to main content

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

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

starlette_feedgen-0.1.4.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

starlette_feedgen-0.1.4-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file starlette_feedgen-0.1.4.tar.gz.

File metadata

  • Download URL: starlette_feedgen-0.1.4.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Darwin/21.6.0

File hashes

Hashes for starlette_feedgen-0.1.4.tar.gz
Algorithm Hash digest
SHA256 4e6eec985629b1bb1b6e9a7c006c762425754a67e379a485f7ad08d4c751e2a5
MD5 a94bc6ad4fc93c37bee239007234578a
BLAKE2b-256 36a43d7fafc98402cdadaa0da978a3804ba17f28d039d65de98c22f857a77f4a

See more details on using hashes here.

File details

Details for the file starlette_feedgen-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for starlette_feedgen-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a071d6ffbf5e567420073a21f8b69d9fa7bc4843e15b12f847cdc2569d5ee7cd
MD5 2c97894c39c76115eb934cf1a6fc1569
BLAKE2b-256 10c0458fb7889c05cf55e60c5b4262320d48ed10d99242db8fb74555cb76fe61

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page