Items are the fundamental objects returned by Hacker News.

Fetch an Item

item = await hn.item(44321234)

The returned object may be one of:

  • Story
  • Comment
  • Job
  • Poll
  • PollOption

Stories

story = await hn.item(story_id)

print(story.title)
print(story.url)
print(story.score)
print(story.descendants)

Comments

comment = await hn.item(comment_id)

print(comment.text)
print(comment.parent)

Polls

poll = await hn.item(poll_id)

print(poll.parts)

Poll Options

option = await hn.item(option_id)

print(option.score)

Batch Fetching

items = await hn.items(
    [id1, id2, id3]
)

Batch requests execute concurrently.