Coder Social home page Coder Social logo

jsonfeed's Introduction

jsonfeed

PyPI Python 3.6 GitHub Workflow Status (branch) Full package documentation

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.toJSON())

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 nonmeaningful JSON feeds (e.g. with this valid Author object: {}).

Examples

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. Use Feed.authors.
  • Item.author is deprecated. Use Item.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, that version 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.

jsonfeed's People

Contributors

lukasschwab avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

jsonfeed's Issues

Introduce date format validation

Dates in output feeds must be in RFC 3339 form for the feed to be valid.

Either validate the dates or receive datetimes in lieu of strings in constructors.

Add docstrings

Should make the documentation added in #1 significantly more useful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.