SDKs overview

The HackerNews API is an unofficial interface, primarily maintained by the community, that provides read-only access to stories, comments, and user data. It is built on Firebase and offers real-time updates, making it suitable for applications requiring up-to-date information from the platform. While there are no officially developed SDKs by Y Combinator, the open-source community has developed various libraries in multiple programming languages to simplify interaction with this API.

These community-driven SDKs and libraries abstract the direct HTTP requests and Firebase interactions, providing developers with language-specific methods to fetch data such as top stories, new stories, ask stories, show stories, job stories, and individual item details (stories, comments, polls). The API structure follows a simple item-based model, where each story, comment, or user has a unique ID, and related items can be fetched via parent/child relationships.

Developers commonly use these libraries to build custom HackerNews clients, data analysis tools, notification systems, or to integrate HackerNews discussions into other applications. The primary source for understanding the API's structure and endpoints is the HackerNews API GitHub repository, which outlines the available data types and how to access them.

Official SDKs by language

As of 2026, Y Combinator does not provide official SDKs for the HackerNews API. The API itself is described as an "unofficial, community-maintained API" built on Firebase. This means that all existing libraries are developed and maintained by the open-source community rather than by the platform's owners. Developers interact directly with the Firebase-hosted API endpoints or utilize community-contributed libraries that wrap these interactions.

The HackerNews API leverages Firebase's real-time database capabilities, which means that data changes are pushed to connected clients without the need for constant polling. For developers familiar with Firebase, direct integration using a Firebase client library is also an option, as detailed in the Firebase Realtime Database documentation.

Installation

Since there are no official SDKs, installation typically involves using package managers specific to the programming language of the chosen community library. The following table provides examples of common community libraries, their package names, and typical installation commands.

Language Library (Example) Package Manager / Install Command Maturity / Status
Python python-hacker-news pip install python-hacker-news Community-maintained, active
JavaScript (Node.js) hacker-news-api-wrapper npm install hacker-news-api-wrapper Community-maintained, active
Ruby hn_api gem install hn_api Community-maintained, moderate activity
Go go-hn go get github.com/sjparkinson/go-hn Community-maintained, active
PHP hacker-news-api-client composer require phplx/hacker-news-api-client Community-maintained, moderate activity

Before installing any community library, developers are advised to review the library's documentation and GitHub repository for the most up-to-date installation instructions, dependencies, and licensing information. Compatibility with the current HackerNews API structure, as described in the HackerNews API documentation on GitHub, should also be verified.

Quickstart example

This quickstart example demonstrates how to fetch the top stories from the HackerNews API using a common Python community library. This example assumes you have Python installed and the python-hacker-news library installed via pip install python-hacker-news.

Python Example: Fetching Top Stories


import hacker_news as hn

def get_top_stories(limit=10):
    try:
        # Fetch the IDs of the top stories
        top_story_ids = hn.get_top_story_ids()
        print(f"Found {len(top_story_ids)} top story IDs.")

        stories = []
        # Fetch details for a limited number of top stories
        for i, story_id in enumerate(top_story_ids):
            if i >= limit:
                break
            story = hn.get_item(story_id)
            if story:
                stories.append(story)
                print(f"  Story {i+1}: {story.get('title', 'No Title')} (ID: {story_id})")

        return stories

    except Exception as e:
        print(f"An error occurred: {e}")
        return []

if __name__ == "__main__":
    print("Fetching top 5 HackerNews stories...")
    top_5_stories = get_top_stories(limit=5)
    if top_5_stories:
        print("\nSuccessfully fetched top stories. Here's the first one:")
        print(f"Title: {top_5_stories[0].get('title')}")
        print(f"URL: {top_5_stories[0].get('url')}")
        print(f"Score: {top_5_stories[0].get('score')}")
        print(f"By: {top_5_stories[0].get('by')}")
    else:
        print("Could not fetch top stories.")

This script first retrieves a list of IDs for the current top stories. It then iterates through these IDs, fetching the full details for each story up to a specified limit. Each story is an item in the HackerNews API, which can represent a story, comment, poll, or job. The get_item method is used to retrieve the full JSON object for a given ID, as described in the HackerNews API Items section.

JavaScript (Node.js) Example: Fetching New Stories

For a Node.js environment, using a library like hacker-news-api-wrapper would involve similar steps. First, install the package: npm install hacker-news-api-wrapper.


const hn = require('hacker-news-api-wrapper');

async function getNewStories(limit = 5) {
    try {
        const newStoryIds = await hn.getNewStoryIds();
        console.log(`Found ${newStoryIds.length} new story IDs.`);

        const stories = [];
        for (let i = 0; i < Math.min(limit, newStoryIds.length); i++) {
            const storyId = newStoryIds[i];
            const story = await hn.getItem(storyId);
            if (story) {
                stories.push(story);
                console.log(`  Story ${i + 1}: ${story.title || 'No Title'} (ID: ${storyId})`);
            }
        }
        return stories;

    } catch (error) {
        console.error(`An error occurred: ${error}`);
        return [];
    }
}

(async () => {
    console.log("Fetching 5 new HackerNews stories...");
    const new_5_stories = await getNewStories(5);
    if (new_5_stories.length > 0) {
        console("\nSuccessfully fetched new stories. Here's the first one:");
        console.log(`Title: ${new_5_stories[0].title}`);
        console.log(`URL: ${new_5_stories[0].url}`);
        console.log(`Score: ${new_5_stories[0].score}`);
        console.log(`By: ${new_5_stories[0].by}`);
    } else {
        console.log("Could not fetch new stories.");
    }
})();

This JavaScript example fetches the IDs of new stories and then retrieves the details for a specified number of them. Both examples illustrate the pattern of fetching item IDs first and then individual item details, which is a common approach when working with the HackerNews API due to its Firebase backend structure.

Community libraries

The HackerNews ecosystem thrives on community contributions, especially concerning API access. Various developers have created libraries in different programming languages to abstract the direct interaction with the Firebase API endpoints. These libraries often provide convenient methods for fetching various types of stories (top, new, best, ask, show, job), individual item details (stories, comments, polls), and user profiles.

Key considerations when choosing a community library include:

  • Language Support: Libraries are available for popular languages like Python, JavaScript, Ruby, Go, PHP, and more.
  • Maintenance Status: Check the GitHub repository for recent commits, open issues, and pull requests to gauge active maintenance.
  • Features: Some libraries offer more comprehensive features, such as caching, error handling, or specific query parameters, while others provide a more minimal wrapper.
  • Documentation: Well-documented libraries simplify integration and troubleshooting.
  • License: Ensure the library's license is compatible with your project's requirements.

For a comprehensive list of community-contributed libraries and tools, developers can often find curated lists within the HackerNews API GitHub repository or by searching package managers like npm, PyPI, or RubyGems for "HackerNews API" or "HN API" related packages. It's important to verify that any chosen library correctly implements the HackerNews API specifications.

Additionally, developers can directly interact with the Firebase API using general-purpose HTTP clients or Firebase SDKs if a specific language library is not available or if more granular control is required. The Firebase Realtime Database is a NoSQL cloud database, and its official documentation can provide insights into direct data access patterns.