Python package for parsing and generating JSON feeds.
Project description
jsonfeed
jsonfeed
is a Python package for parsing and constructing JSON Feeds. It explicitly supports JSON Feed Version 1.1.
Usage
This package's constructor arguments and class variables exactly match the field names defined in the JSON feed spec. I hope that the code is clear enough that the spec can be its granular documentation.
Installation
Install this package with pip
:
$ pip install jsonfeed-util
In your Python code, include the line
import jsonfeed
Parsing a JSON feed
import jsonfeed as jf
import requests
# Requesting a valid JSON feed!
r = requests.get('https://arxiv-feeds.appspot.com/json/test')
# Parse from raw text...
feed_from_text = jf.Feed.parse_string(r.text)
# ...or parse JSON separately.
r_json = r.json()
feed_from_json = jf.Feed.parse(r_json)
Constructing a JSON feed
import jsonfeed as jf
me = jf.Author(
name="Lukas Schwab",
url="https://github.com/lukasschwab"
)
feed = jf.Feed("My Feed Title", authors=[me])
item = jf.Item("some_item_id")
feed.items.append(item)
print(feed.to_json()
jsonfeed
exposes constructors for five classes of JSON feed objects:
Feed
Author
Hub
Item
Attachment
Note, jsonfeed
is designed to be minimally restrictive. It does not require fields that are not required in the JSON Feed spec. This means it's possible to construct non-meaningful JSON feeds (e.g. with this valid Author
object: {}
).
Examples
arxiv-feeds
: converts Atom to JSON feeds.jsonfeed-wrapper
: converts scraped HTML to JSON feeds.pandoc-blog
: generates a JSON feed for a static site.
Deprecations
See the spec for an overview of deprecated JSON Feed fields. This project (especially the converters
and the parsing functions) will stay backwards-compatible when possible, but using deprecated fields when constructing feeds is discouraged.
JSON Feed 1.1
Feed.author
is deprecated. UseFeed.authors
.Item.author
is deprecated. UseItem.authors
.
Notes
-
Dictionaries maintain insertion order as of Python 3.6.
jsonfeed
takes advantage of this to retain the order suggested in the JSON Feed spec (namely, thatversion
appear at the top of the JSON object). This order may not be enforced in earlier versions of Python, but out-of-order JSON Feeds are not invalid. -
I made a conscious decision to shoot for code that's readable––vis à vis the JSON Feed spec––rather than code that's minimal or performant. Additionally, I opted to avoid dependencies outside of the standard library. Hopefully this makes for easy maintenance.
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
File details
Details for the file jsonfeed-util-1.1.3.tar.gz
.
File metadata
- Download URL: jsonfeed-util-1.1.3.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2575a9f5a9a58e044821932b85e3c3826aef0c16ff569d5bdeae7077100549f |
|
MD5 | 6d1564be71f3ca6e9d41f05614c21107 |
|
BLAKE2b-256 | 2fb8ef92c72271a1da857a10f36fa7a582ca2d4635c276883f9ca29305c7ba75 |